Quantization adjustment based on texture level

ABSTRACT

A video encoder identifies a current smooth region of a current picture in a sequence and performs temporal analysis by determining whether a corresponding region in at least one previous and/or future picture is smooth. Based at least in part on the temporal analysis, the encoder adjusts quantization in the current smooth region. An encoder determines a differential quantization interval for a sequence, the interval comprising an interval number. The interval constrains the encoder to skip differential quantization for at least the interval number of predicted pictures after a predicted differentially quantized picture. An encoder analyzes texture in a current picture and sets a smoothness threshold. The encoder compares texture data with the smoothness threshold and adjusts differential quantization for at least part of the current picture based on a finding of at least one smooth region in the current picture according to the smoothness threshold.

BACKGROUND

With the increased popularity of DVDs, music delivery over the Internet,and digital cameras, digital media have become commonplace. Engineersuse a variety of techniques to process digital audio, video, and imagesefficiently while still maintaining quality. To understand thesetechniques, it helps to understand how the audio, video, and imageinformation is represented and processed in a computer.

I. Representation of Media Information in a Computer

A computer processes media information as a series of numbersrepresenting that information. For example, a single number mayrepresent the intensity of brightness or the intensity of a colorcomponent such as red, green or blue for each elementary small region ofa picture, so that the digital representation of the picture consists ofone or more arrays of such numbers. Each such number may be referred toas a sample. For a color image, it is conventional to use more than onesample to represent the color of each elemental region, and typicallythree samples are used. The set of these samples for an elemental regionmay be referred to as a pixel, where the word “pixel” is a contractionreferring to the concept of a “picture element.” For example, one pixelmay consist of three samples that represent the intensity of red, greenand blue light necessary to represent the elemental region. Such a pixeltype is referred to as an RGB pixel. Several factors affect quality ofmedia information, including sample depth, resolution, and frame rate(for video).

Sample depth is a property normally measured in bits that indicates therange of numbers that can be used to represent a sample. When morevalues are possible for the sample, quality can be higher because thenumber can capture more subtle variations in intensity and/or a greaterrange of values. Resolution generally refers to the number of samplesover some duration of time (for audio) or space (for images orindividual video pictures). Images with higher resolution tend to lookcrisper than other images and contain more discemable useful details.Frame rate is a common term for temporal resolution for video. Videowith higher frame rate tends to mimic the smooth motion of naturalobjects better than other video, and can similarly be considered tocontain more detail in the temporal dimension. For all of these factors,the tradeoff for high quality is the cost of storing and transmittingthe information in terms of the bit rate necessary to represent thesample depth, resolution and frame rate, as Table 1 shows.

TABLE 1 Bit rates for different quality levels of raw video ResolutionBit Rate Bits Per Pixel (in pixels, Frame Rate (in millions (sampledepth times Width × (in frames of bits per samples per pixel) Height)per second) second) 8 (value 0-255, monochrome) 160 × 120 7.5 1.2 24(value 0-255, RGB) 320 × 240 15 27.6 24 (value 0-255, RGB) 640 × 480 30221.2 24 (value 0-255, RGB) 1280 × 720  60 1327.1

Despite the high bit rate necessary for storing and sending high qualityvideo (such as HDTV), companies and consumers increasingly depend oncomputers to create, distribute, and play back high quality content. Forthis reason, engineers use compression (also called source coding orsource encoding) to reduce the bit rate of digital media. Compressiondecreases the-cost of storing and transmitting the information byconverting the information into a lower bit rate form. Compression canbe lossless, in which quality of the video does not suffer but decreasesin bit rate are limited by the complexity of the video. Or, compressioncan be lossy, in which quality of the video suffers but decreases in bitrate are more dramatic. Decompression (also called decoding)reconstructs a version of the original information from the compressedform. A “codec” is an encoder/decoder system.

In general, video compression techniques include “intra” compression and“inter” or predictive compression. For video frames, intra compressiontechniques compress individual frames, typically called I-frames or keyframes. Inter compression techniques compress frames with reference topreceding and/or following frames, and inter-compressed frames aretypically called predicted frames, P-frames, or B-frames.

II. Inter and Intra Compression in Windows Media Video, Versions 8 and 9

Microsoft Corporation's Windows Media Video, Version 8 [“WMV8”] includesa video encoder and a video decoder. The WMV8 encoder uses intra andinter compression, and the WMV8 decoder uses intra and interdecompression. Windows Media Video, Version 9 [“WMV9”] uses a similararchitecture for many operations.

A. Intra Compression

FIG. 1 illustrates block-based intra compression 100 of a block 105 ofsamples in a key frame in the WMV8 encoder. A block is a set of samples,for example, an 8×8 arrangement of samples. The WMV8 encoder splits akey video frame into 8×8 blocks and applies an 8×8 Discrete CosineTransform [“DCT”] 110 to individual blocks such as the block 105. A DCTis a type of frequency transform that converts the 8×8 block of samples(spatial information) into an 8×8 block of DCT coefficients 115, whichare frequency information. The DCT operation itself is lossless ornearly lossless. Compared to the original sample values, however, theDCT coefficients are more efficient for the encoder to compress sincemost of the significant information is concentrated in low frequencycoefficients (conventionally, the upper left of the block 115) and manyof the high frequency coefficients (conventionally, the lower right ofthe block 115) have values of zero or close to zero.

The encoder then quantizes 120 the DCT coefficients, resulting in an 8×8block of quantized DCT coefficients 125. Quantization is lossy. Sincelow frequency DCT coefficients tend to have higher values, quantizationtypically results in loss of precision but not complete loss of theinformation for the coefficients. On the other hand, since highfrequency DCT coefficients tend to have values of zero or close to zero,quantization of the high frequency coefficients typically results incontiguous regions of zero values. In addition, in some cases highfrequency DCT coefficients are quantized more coarsely than lowfrequency DCT coefficients, resulting in greater loss ofprecision/information for the high frequency DCT coefficients.

The encoder then prepares the 8×8 block of quantized DCT coefficients125 for entropy encoding, which is a form of lossless compression. Theexact type of entropy encoding can vary depending on whether acoefficient is a DC coefficient (lowest frequency), an AC coefficient(other frequencies) in the top row or left column, or another ACcoefficient.

The encoder encodes the DC coefficient 126 as a differential from the DCcoefficient 136 of a neighboring 8×8 block, which is a previouslyencoded neighbor (e.g., top or left) of the block being encoded. (FIG. 1shows a neighbor block 135 that is situated to the left of the blockbeing encoded in the frame.) The encoder entropy encodes 140 thedifferential.

The entropy encoder can encode the left column or top row of ACcoefficients as a differential from a corresponding left column or toprow of the neighboring 8×8 block. This is an example of AC coefficientprediction. FIG. 1 shows the left column 127 of AC coefficients encodedas a differential 147 from the left column 137 of the neighboring (inreality, to the left) block 135. The differential coding increases thechance that the differential coefficients have zero values. Theremaining AC coefficients are from the block 125 of quantized DCTcoefficients.

The encoder scans 150 the 8×8 block 145 of quantized AC DCT coefficientsinto a one-dimensional array 155 and then entropy encodes the scanned ACcoefficients using a variation of run length coding 160. The encoderselects an entropy code from one or more run/level/last tables 165 andoutputs the entropy code.

B. Inter Compression

Inter compression in the WMV8 encoder uses block-based motioncompensated prediction coding followed by transform coding of theresidual error. FIGS. 2 and 3 illustrate the block-based intercompression for a predicted frame in the WMV8 encoder. In particular,FIG. 2 illustrates motion estimation for a predicted frame 210 and FIG.3 illustrates compression of a prediction residual for amotion-compensated block of a predicted frame.

For example, in FIG. 2, the WMV8 encoder computes a motion vector for amacroblock 215 in the predicted frame 210. To compute the motion vector,the encoder searches in a search area 235 of a reference frame 230.Within the search area 235, the encoder compares the macroblock 215 fromthe predicted frame 210 to various candidate macroblocks in order tofind a candidate macroblock that is a good match. The encoder outputsinformation specifying the motion vector (entropy coded) for thematching macroblock. The motion vector is differentially coded withrespect to a motion vector predictor.

After reconstructing the motion vector by adding the differential to themotion vector predictor, a decoder uses the motion vector to compute aprediction macroblock for the macroblock 215 using information from thereference frame 230, which is a previously reconstructed frame availableat the encoder and the decoder. The prediction is rarely perfect, so theencoder usually encodes blocks of pixel differences (also called theerror or residual blocks) between the prediction macroblock and themacroblock 215 itself.

FIG. 3 illustrates an example of computation and encoding of an errorblock 335 in the WMV8 encoder. The error block 335 is the differencebetween the predicted block 315 and the original current block 325. Theencoder applies a DCT 340 to the error block 335, resulting in an 8×8block 345 of coefficients. The encoder then quantizes 350 the DCTcoefficients, resulting in an 8×8 block of quantized DCT coefficients355. The encoder scans 360 the 8×8 block 355 into a one-dimensionalarray 365 such that coefficients are generally ordered from lowestfrequency to highest frequency. The encoder entropy encodes the scannedcoefficients using a variation of run length coding 370. The encoderselects an entropy code from one or more run/level/last tables 375 andoutputs the entropy code.

FIG. 4 shows an example of a corresponding decoding process 400 for aninter-coded block. In summary of FIG. 4, a decoder decodes (410, 420)entropy-coded information representing a prediction residual usingvariable length decoding 410 with one or more run/level/last tables 415and run length decoding 420. The decoder inverse scans 430 aone-dimensional array 425, storing the entropy-decoded information intoa two-dimensional block 435. The decoder inverse quantizes and inverseDCTs (together, 440) the data, resulting in a reconstructed error block445. In a separate motion compensation path, the decoder computes apredicted block 465 using motion vector information 455 for displacementfrom a reference frame. The decoder combines 470 the predicted block 465with the reconstructed error block 445 to form the reconstructed block475. An encoder also performs the inverse quantization, inverse DCT,motion compensation and combining to reconstruct frames for use asreference frames.

III. Lossy Compression and Quantization

The preceding section mentioned quantization, a mechanism for lossycompression, and entropy coding, also called lossless compression.Lossless compression reduces the bit rate of information by removingredundancy from the information without any reduction in fidelity. Forexample, a series of ten consecutive pixels that are all exactly thesame shade of red could be represented as a code for the particularshade of red and the number ten as a “run length” of consecutive pixels,and this series can be perfectly reconstructed by decompression from thecode for the shade of red and the indicated number (ten) of consecutivepixels having that shade of red. Lossless compression techniques reducebit rate at no cost to quality, but can only reduce bit rate up to acertain point. Decreases in bit rate are limited by the inherent amountof variability in the statistical characterization of the input data,which is referred to as the source entropy.

In contrast, with lossy compression, the quality suffers somewhat butthe achievable decrease in bit rate is more dramatic. For example, aseries of ten pixels, each being a slightly different shade of red, canbe approximated as ten pixels with exactly the same particularapproximate red color. Lossy compression techniques can be used toreduce bit rate more than lossless compression techniques, but some ofthe reduction in bit rate is achieved by reducing quality, and the lostquality cannot be completely recovered. Lossy compression is often usedin conjunction with lossless compression—in a system design in which thelossy compression establishes an approximation of the information andlossless compression techniques are applied to represent theapproximation. For example, the series of ten pixels, each a slightlydifferent shade of red, can be represented as a code for one particularshade of red and the number ten as a run-length of consecutive pixels.In general, an encoder varies quantization to trade off quality and bitrate. Coarser quantization results in greater quality reduction butallows for greater bit rate reduction. In decompression, the originalseries would then be reconstructed as ten pixels with the sameapproximated red color.

According to one possible definition, quantization is a term used for anapproximating non-reversible mapping function commonly used for lossycompression, in which there is a specified set of possible outputvalues, and each member of the set of possible output values has anassociated set of input values that result in the selection of thatparticular output value. A variety of quantization techniques have beendeveloped, including scalar or vector, uniform or non-uniform, andadaptive or non-adaptive quantization.

A. Scalar Quantizers

According to one possible definition, a scalar quantizer is anapproximating functional mapping x→Q[x] of an input value x to aquantized value Q[x], sometimes called a reconstructed value. FIG. 5shows a “staircase” I/O function 500 for a scalar quantizer. Thehorizontal axis is a number line for a real number input variable x, andthe vertical axis indicates the corresponding quantized values Q[x]. Thenumber line is partitioned by thresholds such as the threshold 510. Eachvalue of x within a given range between a pair of adjacent thresholds isassigned the same quantized value Q[x]. For example, each value of xwithin the range 520 is assigned the same quantized value 530. (At athreshold, one of the two possible quantized values is assigned to aninput x, depending on the system.) Overall, the quantized values Q[x]exhibit a discontinuous, staircase pattern. The distance the mappingcontinues along the number line depends on the system, typically endingafter a finite number of thresholds. The placement of the thresholds onthe number line may be uniformly spaced (as shown in FIG. 5) ornon-uniformly spaced.

A scalar quantizer can be decomposed into two distinct stages. The firststage is the classifier stage, in which a classifier function mappingx→A [x] maps an input x to a quantization index A[x], which is ofteninteger-valued. In essence, the classifier segments an input number lineor data set. FIG. 6A shows a generalized classifier 600 and thresholdsfor a scalar quantizer. As in FIG. 5, a number line for a real numbervariable x is segmented by thresholds such as the threshold 610. Eachvalue of x within a given range such as the range 620 is assigned thesame quantized value Q[x]. FIG. 6B shows a numerical example of aclassifier 650 and thresholds for a scalar quantizer.

In the second stage, a reconstructor functional mapping k→β[k] maps eachquantization index k to a reconstruction value β[k]. In essence, thereconstructor places steps having a particular height relative to theinput number line segments (or selects a subset of data set values) forreconstruction of each region determined by the classifier. Thereconstructor functional mapping may be implemented, for example, usinga lookup table. Overall, the classifier relates to the reconstructor asfollows:Q[x]=β[A[x]]  (1).

In common usage, the term “quantization” is often used to describe theclassifier stage, which is performed during encoding. The term “inversequantization” is similarly used to describe the reconstructor stage,whether performed during encoding or decoding.

The distortion introduced by using such a quantizer may be computed witha difference-based distortion measure d(x−Q[x]). Typically, such adistortion measure has the property that d(x−Q[x]) increases as x−Q[x]deviates from zero; and typically each reconstruction value lies withinthe range of the corresponding classification region, so that thestraight line that would be formed by the functional equation Q[x] =xwill pass through every step of the staircase diagram (as shown in FIG.5) and therefore Q[Q[x]] will typically be equal to Q[x]. In general, aquantizer is considered better in rate-distortion terms if the quantizerresults in a lower average value of distortion than other quantizers fora given bit rate of output. More formally, a quantizer is consideredbetter if, for a source random variable X, the expected (i.e., theaverage or statistical mean) value of the distortion measureD=E_(x){d(X−Q[X])} is lower for an equal or lower entropy H of A[X]. Themost commonly-used distortion measure is the squared error distortionmeasure, for which d(|x−y|)=|x−y|². When the squared error distortionmeasure is used, the expected value of the distortion measure ( D) isreferred to as the mean squared error.

B. Dead Zone+Uniform Threshold Quantizers

A non-uniform quantizer has threshold values that are not uniformlyspaced for all classifier regions. According to one possible definition,a dead zone plus uniform threshold quantizer [“DZ+UTQ”] is a quantizerwith uniformly spaced threshold values for all classifier regions exceptthe one containing the zero input value (which is called the dead zone[“DZ”]). In a general sense, a DZ+UTQ is a non-uniform quantizer, sincethe DZ size is different than the other classifier regions.

A DZ+UTQ has a classifier index mapping rule x→A[x] that can beexpressed based on two parameters. FIG. 7 shows a staircase I/O function700 for a DZ+UTQ, and FIG. 8A shows a generalized classifier 800 andthresholds for a DZ+UTQ. The parameter s, which is greater than 0,indicates the step size for all steps other than the DZ. Mathematically,all s_(i) are equal to s for i≠0. The parameter z, which is greater thanor equal to 0, indicates the ratio of the DZ size to the size of theother steps. Mathematically, s₀=z·s. In FIG. 8A, z is 2, so the DZ istwice as wide as the other classification zones.

The index mapping rule x→A[x] for a DZ+UTQ can be expressed as:

$\begin{matrix}{{{A\lbrack x\rbrack} = {{{sign}(x)}*{\max\left( {0,\left\lfloor {\frac{x}{s} - \frac{z}{2} + 1} \right\rfloor} \right)}}},} & (2)\end{matrix}$where [·] denotes the smallest integer less than or equal to theargument and where sign(x) is the function defined as:

$\begin{matrix}{{{sign}(x)} = \left\{ {\begin{matrix}{{+ 1},} & {{{{for}\mspace{14mu} x} \geq 0},} \\{{- 1},} & {{{for}\mspace{14mu} x} < 0.}\end{matrix}.} \right.} & (3)\end{matrix}$

FIG. 8B shows a numerical example of a classifier 850 and thresholds fora DZ+UTQ with s=1 and z=2. FIGS. 5, 6A, and 6B show a special caseDZ+UTQ with z=1. Quantizers of the UTQ form have good performance for avariety of statistical sources. In particular, the DZ+UTQ form isoptimal for the statistical random variable source known as theLaplacian source.

In some system designs (not shown), an additional consideration may benecessary to fully characterize a DZ+UTQ classification rule. Forpractical reasons there may be a need to limit the range of values thatcan result from the classification function A[x] to some reasonablefinite range. This limitation is referred to as clipping. For example,in some 30 such systems the classification rule could more precisely bedefined as:

$\begin{matrix}{{{A\lbrack x\rbrack} = {{{sign}(x)}*{\min\left\lbrack {g,{\max\left( {0,\left\lfloor {\frac{x}{s} - \frac{z}{2} + 1} \right\rfloor} \right)}} \right\rbrack}}},} & (4)\end{matrix}$where g is a limit on the absolute value of A[x].

Different reconstruction rules may be used to determine thereconstruction value for each quantization index. Standards and productspecifications that focus only on achieving interoperability will oftenspecify reconstruction values without necessarily specifying theclassification rule. In other words, some specifications may define thefunctional mapping k→β[k] without defining the functional mappingx→A[x]. This allows a decoder built to comply with thestandard/specification to reconstruct information correctly. Incontrast, encoders are often given the freedom to change the classifierin any way that they wish, while still complying with thestandard/specification.

Numerous systems for adjusting quantization thresholds have beendeveloped. Many standards and products specify reconstruction valuesthat correspond to a typical mid-point reconstruction rule (e.g., for atypical simple classification rule) for the sake of simplicity. Forclassification, however, the thresholds can in fact be adjusted so thatcertain input values will be mapped to more common (and hence, lower bitrate) indices, which makes the reconstruction values closer to optimal.

In many systems, the extent of quantization is measured in terms ofquantization step size. Coarser quantization uses larger quantizationstep sizes, corresponding to wider ranges of input values. Finerquantization uses smaller quantization step sizes. Often, for purposesof signaling and reconstruction, quantization step sizes areparameterized as multiples of a smallest quantization step size.

C. Quantization Artifacts

As mentioned above, lossy compression tends to cause a decrease inquality. For example, a series of ten samples of slightly differentvalues can be approximated using quantization as ten samples withexactly the same particular approximate value. This kind of quantizationcan reduce the bit rate of encoding the series of ten samples, but atthe cost of lost detail in the original ten samples.

In some cases, quantization produces visible artifacts that tend to bemore artificial-looking and visually distracting than simple loss offine detail. For example, smooth, un-textured content is susceptible tocontouring artifacts—artifacts that appear between regions of twodifferent quantization output values—because the human visual system issensitive to subtle variations (particularly luma differences) in smoothcontent. Using the above example, consider a case where the luma valuesof the series of ten samples change gradually and consistently from thefirst sample to the tenth sample. Quantization may approximate the firstfive sample values as one value and the last five sample values asanother value. While this kind of quantization may not create visibleartifacts in textured areas due to masking effects, in smooth regions itcan create a visible line or step in the reconstructed image between thetwo sets of five samples.

IV. Differential Quantization in VC-1

In differential quantization, an encoder varies quantization step sizes(also referred to herein as quantization parameters or QPs in someimplementations) for different parts of a picture. Typically, thisinvolves varying QPs on a macroblock level or other sub-picture level.The encoder makes decisions on how to vary the QPs, and signals thosedecisions, as appropriate, to a decoder.

For example, a VC-1 encoder optionally chooses differential quantizationfor compression. The encoder sends a bitstream element (DQUANT) at asyntax level above picture level to indicate whether or not the QP canvary among the macroblocks in individual pictures. The encoder sends apicture-level bitstream element, PQJNDEX, to indicate a picture QP. IfDQUANT=0, the QP indicated by PQINDEX is used for all macroblocks in thepicture. If DQUANT=1 or 2, different macroblocks in the same picture canuse different QPs.

The VC-1 encoder can use more than one approach to differentialquantization. In one approach, only two different QPs are used for apicture. This is referred to as bi-level differential quantization. Forexample, one QP is used for macroblocks at picture edges and another QPis used for macroblocks in the rest of the picture. This can be usefulfor saving bits at picture edges, where fine detail is less importantfor maintaining overall visual quality. Or, a 1-bit value signaled permacroblock indicates which of two available QP values to use for themacroblock. In another approach, referred to as multi-level differentialquantization, a larger number of different QPs can be used forindividual macroblocks in a picture.

The encoder sends a picture-level bitstream element, VOPDQUANT, whenDQUANT is non-zero. VOPDQUANT is composed of other elements, potentiallyincluding DQPROFILE, which indicates which parts of the picture can useQPs other than the picture QP. When DQPROFILE indicates that arbitrary,different macroblocks can use QPs other than the picture QP, thebitstream element DQBILEVEL is present. If DQBILEVEL=1, each macroblockuses one of two QPs (bi-level quantization). If DQBILEVEL=0, eachmacroblock can use any QP (multi-level quantization).

The bitstream element MQDIFF is sent at macroblock level to signal a1-bit selector for a macroblock for bi-level quantization. Formulti-level quantization, MQDIFF indicates a differential between thepicture QP and the macroblock QP or escape-coded absolute QP for amacroblock.

V. Other Standards and Products

Numerous international standards specify aspects of video decoders andformats for compressed video information. Directly or by implication,these standards also specify certain encoder details, but other encoderdetails are not specified. Some standards address still imagecompression/decompression, and other standards address audiocompression/decompression. Numerous companies have produced encoders anddecoders for audio, still images, and video. Various other kinds ofsignals (for example, hyperspectral imagery, graphics, text, financialinformation, etc.) are also commonly represented and stored ortransmitted using compression techniques.

Various video standards allow the use of different quantization stepsizes for different picture types, and allow variation of quantizationstep sizes for rate and quality control.

Standards typically do not fully specify the quantizer design. Mostallow some variation in the encoder classification rule x→A [x] and/orthe decoder reconstruction rule k→β[k]. The use of a DZ ratio z=2 orgreater has been implicit in a number of encoding designs. For example,the spacing of reconstruction values for predicted regions in somestandards implies use of z≧2. Reconstruction values in these examplesfrom standards are spaced appropriately for use of DZ+UTQ classificationwith z=2. Designs based on z=1 (or at least z<2) have been used forquantization in several standards. In these cases, reconstruction valuesare equally spaced around zero and away from zero.

Given the critical importance of video compression to digital video, itis not surprising that video compression is a richly developed field.Whatever the benefits of previous video compression techniques, however,they do not have the advantages of the following techniques and tools.

SUMMARY

The present application describes techniques and tools for adjustingquantization based on texture levels in video. For example, a videoencoder improves the perceptual quality of video using adaptivesmoothness thresholds for smooth regions and temporal analysis of smoothregions when allocating bits during encoding.

This Summary is provided to introduce a selection of concepts in asimplified form that are further described below in the DetailedDescription. This Summary is not intended to identify key features oressential features of the claimed subject matter, nor is it intended tobe used to limit the scope of the claimed subject matter.

In one aspect, a video encoder identifies a current smooth region (e.g.,a gradient slope region) of a current video picture in a video picturesequence. The sequence has a display order in which display of previouspictures occurs before display of the current picture and display offuture pictures occurs after the display of the current picture. Theencoder performs temporal analysis on the current smooth region. Thetemporal analysis comprises determining whether a corresponding regionin at least one of the previous and/or future pictures is smooth. Basedat least in part on the temporal analysis, the encoder adjustsquantization (e.g., reducing a quantization step size to avoidintroduction of a contouring artifact) in the current smooth region. Thetemporal analysis can be performed on an adjustable number of futurepictures. The temporal analysis can attribute greater weight tosmoothness in a corresponding region of a future picture that istemporally nearer to the current picture. The encoder can analyze atexture map to identify the current smooth region, and can analyze meanluminance values in the temporal analysis.

In another aspect, a video encoder determines a differentialquantization interval (e.g., a fixed or adaptively adjustable interval)for a video picture sequence, the interval comprising an intervalnumber. The encoder uses the interval when performing differentialquantization for predicted differentially quantized pictures in thesequence. The interval constrains the encoder to skip differentialquantization for at least the interval number of predicted picturesafter one of the predicted differentially quantized pictures. Forexample, the differential quantization comprises selecting one or moredifferential quantization step sizes for a first predicted picture andchanging the one or more differential quantization step sizes for asecond predicted picture, where the one or more differentialquantization step sizes differ from a picture quantization step size forthe first predicted picture, and the second predicted picture is outsidethe interval from the first predicted picture.

In another aspect, a video encoder analyzes texture in a current videopicture (e.g., by analyzing a texture map) and sets a smoothnessthreshold for the current picture based at least in part on the analyzedtexture. The encoder compares texture data of the current picture withthe smoothness threshold and adjusts differential quantization for atleast part of the current picture based on a finding of at least onesmooth region in the current picture according to the smoothnessthreshold. The encoder can analyze texture by applying a sliding windowto a gradient value histogram of block gradient values. To adjustdifferential quantization, the encoder can determine a percentage offlat blocks in the current picture and compare the percentage to one ormore percentage thresholds. Or, the encoder can identify an isolatedflat block in a texture region in the current picture and skipdifferential quantization for the isolated flat block.

The foregoing and other objects, features, and advantages will becomemore apparent from the following detailed description, which proceedswith reference to the accompanying figures.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a diagram showing block-based intraframe compression of an 8×8block of samples.

FIG. 2 is a diagram showing motion estimation in a video encoder.

FIG. 3 is a diagram showing block-based compression for an 8×8 block ofprediction residuals in a video encoder.

FIG. 4 is a diagram showing block-based decompression for an 8×8 blockof prediction residuals in a video decoder.

FIG. 5 is a chart showing a staircase I/O function for a scalarquantizer.

FIGS. 6A and 6B are charts showing classifiers and thresholds for scalarquantizers.

FIG. 7 is a chart showing a staircase I/O function for a DZ+UTQ.

FIGS. 8A and 8B are charts showing classifiers and thresholds forDZ+UTQs.

FIG. 9 is a block diagram of a suitable computing environment inconjunction with which several described embodiments may be implemented.

FIG. 10 is a block diagram of a generalized video encoder system inconjunction with which several described embodiments may be implemented.

FIG. 11 is a diagram of a macroblock format used in several describedembodiments.

FIG. 12 is a flow chart of an adaptive video encoding method.

FIG. 13 is a diagram showing computation of a pixel gradient usingluminance and chrominance data for a block.

FIG. 14 is a histogram graph of plural pixel gradients for the block ofFIG. 13.

FIG. 15 is a graph of an example block value characterization framework.

FIG. 16 is a flow chart showing a generalized technique for applyingdifferential quantization based on texture information.

FIG. 17 is a flow chart showing a technique for using temporal analysisto make texture DQ decisions.

FIG. 18 is a flow chart showing a technique for making a texture DQdecision using percentage thresholds and isolated smooth blockfiltering.

FIG. 19 is a flow chart showing a technique for selectively adjustingtexture level thresholds for high-texture pictures.

FIG. 20 is a code diagram showing example pseudo-code for determining anadaptive texture-level threshold.

FIG. 21 is a diagram showing two examples of gradient slope regions.

FIG. 22A is a diagram showing an example frame with a gradient sloperegion, a textured region, a sharp-edge region and a flat region. FIG.22B is a diagram showing a contouring artifact in the gradient sloperegion of FIG. 22A. FIG. 22C shows macroblock-level detail of acontouring artifact of FIG. 22B.

FIG. 23 is a flow chart showing a generalized region-based gradientslope detection technique.

FIG. 24 is a block diagram of an example gradient slope detectoraccording to one implementation.

FIG. 25 is a diagram that depicts 4-to-1 down-sampling of a gradientslope region with film grains that potentially cause anomalous gradientslope directions.

FIG. 26 is an equation diagram for 16x 16 compass operators K_(H) andK_(V).

FIG. 27 is a code diagram showing example pseudo-code for computing thegradient direction for a region using the compass operators of FIG. 26.

FIG. 28 is a flow chart showing a technique for performing consistencychecking for gradient slope regions.

FIG. 29 is a diagram that depicts buckets in a bucket voting technique.

FIG. 30 is a flow chart showing an example technique for selecting amacroblock QP to help preserve one or more non-zero AC coefficients.

FIG. 31 is a diagram showing a DC shift in three neighboring blocks in agradient slope region after quantization and inverse quantization.

FIG. 32 is a flow chart showing a generalized technique for adjustingquantization to reduce or avoid introduction of contouring artifacts inDC shift areas.

FIG. 33 is a flow chart showing a combined technique for tailoringquantization in DC shift areas to reduce or avoid introduction ofquantization artifacts.

DETAILED DESCRIPTION

The present application relates to techniques and tools for efficientcompression of video. In various described embodiments, a video encoderincorporates techniques for encoding video, and corresponding signalingtechniques for use with a bitstream format or syntax comprisingdifferent layers or levels. Some of the described techniques and toolscan be applied to interlaced or progressive frames.

Various alternatives to the implementations described herein arepossible. For example, techniques described with reference to flowchartdiagrams can be altered by changing the ordering of stages shown in theflowcharts, by repeating or omitting certain stages, etc. For example,initial stages an analysis (e.g., obtaining texture information for apicture or performing texture analysis in detecting smooth regions) canbe completed before later stages (e.g., making encoding decisions forthe picture or performing temporal analysis in detecting smooth regions)begin, or operations for the different stages can be interleaved on ablock-by-block, macroblock-by-macroblock, or other region-by-regionbasis. As another example, although some implementations are describedwith reference to specific macroblock formats, other formats also can beused.

The various techniques and tools can be used in combination orindependently. Different embodiments implement one or more of thedescribed techniques and tools. Some techniques and tools describedherein can be used in a video encoder, or in some other system notspecifically limited to video encoding.

I. Computing Environment

FIG. 9 illustrates a generalized example of a suitable computingenvironment 900 in which several of the described embodiments may beimplemented. The computing environment 900 is not intended to suggestany limitation as to scope of use or functionality, as the techniquesand tools may be implemented in diverse general-purpose orspecial-purpose computing environments.

With reference to FIG. 9, the computing environment 900 includes atleast one processing unit 910 and memory 920. In FIG. 9, this most basicconfiguration 930 is included within a dashed line. The processing unit910 executes computer-executable instructions and may be a real or avirtual processor. In a multi-processing system, multiple processingunits execute computer-executable instructions to increase processingpower. The memory 920 may be volatile memory (e.g., registers, cache,RAM), non-volatile memory (e.g., ROM, EEPROM, flash memory, etc.), orsome combination of the two. The memory 920 stores software 980implementing a video encoder with one or more of the describedtechniques and tools.

A computing environment may have additional features. For example, thecomputing environment 900 includes storage 940, one or more inputdevices 950, one or more output devices 960, and one or morecommunication connections 970. An interconnection mechanism (not shown)such as a bus, controller, or network interconnects the components ofthe computing environment 900. Typically, operating system software (notshown) provides an operating environment for other software executing inthe computing environment 900, and coordinates activities of thecomponents of the computing environment 900.

The storage 940 may be removable or non-removable, and includes magneticdisks, magnetic tapes or cassettes, CD-ROMs, DVDs, or any other mediumwhich can be used to store information and which can be accessed withinthe computing environment 900. The storage 940 stores instructions forthe software 980 implementing the video encoder.

The input device(s) 950 may be a touch input device such as a keyboard,mouse, pen, or trackball, a voice input device, a scanning device, oranother device that provides input to the computing environment 900. Foraudio or video encoding, the input device(s) 950 may be a sound card,video card, TV tuner card, or similar device that accepts audio or videoinput in analog or digital form, or a CD-ROM or CD-RW that reads audioor video samples into the computing environment 900. The outputdevice(s) 960 may be a display, printer, speaker, CD-writer, or anotherdevice that provides output from the computing environment 900.

The communication connection(s) 970 enable communication over acommunication medium to another computing entity. The communicationmedium conveys information such as computer-executable instructions,audio or video input or output, or other data in a modulated datasignal. A modulated data signal is a signal that has one or more of itscharacteristics set or changed in such a manner as to encode informationin the signal. By way of example, and not limitation, communicationmedia include wired or wireless techniques implemented with anelectrical, optical, RF, infrared, acoustic, or other carrier.

The techniques and tools can be described in the general context ofcomputer-readable media. Computer-readable media are any available mediathat can be accessed within a computing environment. By way of example,and not limitation, with the computing environment 900,computer-readable media include memory 920, storage 940, communicationmedia, and combinations of any of the above.

The techniques and tools can be described in the general context ofcomputer-executable instructions, such as those included in programmodules, being executed in a computing environment on a target real orvirtual processor. Generally, program modules include routines,programs, libraries, objects, classes, components, data structures, etc.that perform particular tasks or implement particular abstract datatypes. The functionality of the program modules may be combined or splitbetween program modules as desired in various embodiments.Computer-executable instructions for program modules may be executedwithin a local or distributed computing environment.

For the sake of presentation, the detailed description uses terms like“decide” and “analyze” to describe computer operations in a computingenvironment. These terms are high-level abstractions for operationsperformed by a computer, and should not be confused with acts performedby a human being. The actual computer operations corresponding to theseterms vary depending on implementation.

II. Generalized Video Encoder

FIG. 10 is a block diagram of a generalized video encoder 1000 inconjunction with which some described embodiments may be implemented.The encoder 1000 receives a sequence of video pictures including acurrent picture 1005 and produces compressed video information 1095 asoutput to storage, a buffer, or a communication connection. The formatof an output bitstream can be a Windows Media Video or VC-1 format,MPEG-x format (e.g., MPEG-1, MPEG-2, or MPEG-4), H.26x format (e.g.,H.261, H.262, H.263, or H.264), or other format.

The encoder 1000 processes video pictures. The term picture generallyrefers to source, coded or reconstructed image data. For progressivevideo, a picture is a progressive video frame. For interlaced video, apicture may refer to an interlaced video frame, the top field of theframe, or the bottom field of the frame, depending on the context. Theencoder 1000 is block-based and uses a 4:2:0 macroblock format forframes. As shown in FIG. 11, macroblock 1100 includes four 8×8 luminance(or luma) blocks (Y1 through Y4) and two 8×8 chrominance (or chroma)blocks (U and V) that are co-located with the four luma blocks but halfresolution horizontally and vertically, following the conventional 4:2:0macroblock format. For fields, the same or a different macroblockorganization and format may be used. The 8×8 blocks may be furthersub-divided at different stages, e.g., at the frequency transform andentropy encoding stages. The encoder 1000 can perform operations on setsof samples of different size or configuration than 8×8 blocks and 16×16macroblocks. Alternatively, the encoder 1000 is object-based or uses adifferent macroblock or block format.

Returning to FIG. 10, the encoder system 1000 compresses predictedpictures and intra-coded, key pictures. For the sake of presentation,FIG. 10 shows a path for key pictures through the encoder system 1000and a path for predicted pictures. Many of the components of the encodersystem 1000 are used for compressing both key pictures and predictedpictures. The exact operations performed by those components can varydepending on the type of information being compressed.

A predicted picture (e.g., progressive P-frame or B-frame, interlacedP-field or B-field, or interlaced P-frame or B-frame) is represented interms of prediction (or difference) from one or more other pictures(which are typically referred to as reference pictures or anchors). Aprediction residual is the difference between what was predicted and theoriginal picture. In contrast, a key picture (e.g., progressive I-frame,interlaced I-field, or interlaced I-frame) is compressed withoutreference to other pictures.

If the current picture 1005 is a predicted picture, a motion estimator1010 estimates motion of macroblocks or other sets of samples of thecurrent picture 1005 with respect to one or more reference pictures, forexample, the reconstructed previous picture 1025 buffered in the picturestore 1020. If the current picture 1005 is a bi-predictive picture, amotion estimator 1010 estimates motion in the current picture 1005 withrespect to up to four reconstructed reference pictures (for aninterlaced B-field, for example). Typically, a motion estimatorestimates motion in a B-picture with respect to one or more temporallyprevious reference pictures and one or more temporally future referencepictures, but B-pictures need not be predicted from different temporaldirections. The encoder system 1000 can use the separate stores 1020 and1022 for multiple reference pictures.

The motion estimator 1010 can estimate motion by full-sample, ½-sample,¼-sample, or other increments, and can switch the precision of themotion estimation on a picture-by-picture basis or other basis. Themotion estimator 1010 (and compensator 1030) also can switch betweentypes of reference picture sample interpolation (e.g., between bicubicand bilinear) on a per-frame or other basis. The precision of the motionestimation can be the same or different horizontally and vertically. Themotion estimator 1010 outputs as side information motion information1015 such as differential motion vector information. The encoder 1000encodes the motion information 1015 by, for example, computing one ormore predictors for motion vectors, computing differentials between themotion vectors and predictors, and entropy coding the differentials. Toreconstruct a motion vector, a motion compensator 1030 combines apredictor with differential motion vector information.

The motion compensator 1030 applies the reconstructed motion vector tothe reconstructed picture(s) 1025 to form a motion-compensated currentpicture 1035. The prediction is rarely perfect, however, and thedifference between the motion-compensated current picture 1035 and theoriginal current picture 1005 is the prediction residual 1045. Duringlater reconstruction of the picture, the prediction residual 1045 isadded to the motion compensated current picture 1035 to obtain areconstructed picture that is closer to the original current picture1005. In lossy compression, however, some information is still lost fromthe original current picture 1005. Alternatively, a motion estimator andmotion compensator apply another type of motion estimation/compensation.

A frequency transformer 1060 converts the spatial domain videoinformation into frequency domain (i.e., spectral) data. For block-basedvideo pictures, the frequency transformer 1060 applies a DCT, variant ofDCT, or other block transform to blocks of the sample data or predictionresidual data, producing blocks of frequency transform coefficients.Alternatively, the frequency transformer 1060 applies anotherconventional frequency transform such as a Fourier transform or useswavelet or sub-band analysis. The frequency transformer 1060 may applyan 8×8, 8×4, 4×8, 4×4 or other size frequency transform.

A quantizer 1070 then quantizes the blocks of spectral datacoefficients. The quantizer applies uniform, scalar quantization to thespectral data with a step-size that varies on a picture-by-picture basisor other basis (e.g., a macroblock-by-macroblock basis). Alternatively,the quantizer applies another type of quantization to the spectral datacoefficients, for example, a non-uniform, vector, or non-adaptivequantization, or directly quantizes spatial domain data in an encodersystem that does not use frequency transformations. Techniques and toolsrelating to quantization in some implementations are described in detailbelow.

In addition to adaptive quantization, the encoder 1000 can use framedropping, adaptive filtering, or other techniques for rate control.

The encoder 1000 may use special signaling for a skipped macroblock,which is a macroblock that has no information of certain types (e.g., nodifferential motion vectors for the macroblock and no residualinformation).

When a reconstructed current picture is needed for subsequent motionestimation/compensation, an inverse quantizer 1076 performs inversequantization on the quantized spectral data coefficients. An inversefrequency transformer 1066 then performs the inverse of the operationsof the frequency transformer 1060, producing a reconstructed predictionresidual (for a predicted picture) or a reconstructed key picture. Ifthe current picture 1005 was a key picture, the reconstructed keypicture is taken as the reconstructed current picture (not shown). Ifthe current picture 1005 was a predicted picture, the reconstructedprediction residual is added to the motion-compensated current picture1035 to form the reconstructed current picture. One or both of thepicture stores 1020, 1022 buffers the reconstructed current picture foruse in motion compensated prediction. In some embodiments, the encoderapplies a de-blocking filter to the reconstructed frame to adaptivelysmooth discontinuities and other artifacts in the picture.

The entropy coder 1080 compresses the output of the quantizer 1070 aswell as certain side information (e.g., motion information 1015,quantization step size (QP)). Typical entropy coding techniques includearithmetic coding, differential coding, Huffinan coding, run lengthcoding, LZ coding, dictionary coding, and combinations of the above. Theentropy coder 1080 typically uses different coding techniques fordifferent kinds of information (e.g., DC coefficients, AC coefficients,different kinds of side information), and can choose from among multiplecode tables within a particular coding technique.

The entropy coder 1080 provides compressed video information 1095 to themultiplexer (“MUX”) 1090. The MUX 1090 may include a buffer, and abuffer level indicator may be fed back to a controller. Before or afterthe MUX 1090, the compressed video information 1095 can be channel codedfor transmission over the network. The channel coding can apply errordetection and correction data to the compressed video information 1095.

A controller (not shown) receives inputs from various modules such asthe motion estimator 1010, frequency transformer 1060, quantizer 1070,inverse quantizer 1076, entropy coder 1080, and buffer 1090. Thecontroller evaluates intermediate results during encoding, for example,estimating distortion and performing other rate-distortion analysis. Thecontroller works with modules such as the motion estimator 1010,frequency transformer 1060, quantizer 1070, and entropy coder 1080 toset and change coding parameters during encoding. When an encoderevaluates different coding parameter choices during encoding, theencoder may iteratively perform certain stages (e.g., quantization andinverse quantization) to evaluate different parameter settings. Theencoder may set parameters at one stage before proceeding to the nextstage. Or, the encoder may jointly evaluate different coding parameters.The tree of coding parameter decisions to be evaluated, and the timingof corresponding encoding, depends on implementation.

The relationships shown between modules within the encoder 1000 indicategeneral flows of information in the encoder; other relationships are notshown for the sake of simplicity. In particular, FIG. 10 usually doesnot show side information indicating the encoder settings, modes,tables, etc. used for a video sequence, picture, macroblock, block, etc.Such side information, once finalized, is sent in the output bitstream,typically after entropy encoding of the side information.

Particular embodiments of video encoders typically use a variation orsupplemented version of the generalized encoder 1000. Depending onimplementation and the type of compression desired, modules of theencoder can be added, omitted, split into multiple modules, combinedwith other modules, and/or replaced with like modules. For example, thecontroller can be split into multiple controller modules associated withdifferent modules of the encoder. In alternative embodiments, encoderswith different modules and/or other configurations of modules performone or more of the described techniques.

III. Characterization of Video Content Using a Perceptual Model

Video content can be characterized using a perceptual model. This canhelp an encoder to make appropriate encoding decisions for differentkinds of video content. An encoder can analyze a picture before encodingto provide characterizations for the content in different parts of thepicture (e.g., blocks, macroblocks, etc.). For example, relativelysmooth parts of a video picture, such as a blue sky, may becharacterized as less acceptable for introducing distortion becausecertain kinds of quality degradation (e.g., quantization artifacts) aremore easily perceived by humans in smooth regions. In contrast,distortion is generally less noticeable (and thus more acceptable) intexture regions.

With reference to FIG. 12, a video encoder such as one described abovewith reference to FIG. 10 implements adaptive encoding techniques in aprocess 1200 that characterizes portions (e.g., blocks of macroblocks,macroblocks, or other regions) of a video picture (e.g., as a smoothregion, edge region, texture region, etc.) and adapts one or moreencoding techniques according to the characterization. Many of thedescribed techniques provide adaptive encoding within a picture, such ason a block, macroblock or other region. The techniques use informationto classify different parts of the image and to encode them accordingly.More particularly, a video encoder characterizes portions of the pictureto classify content based on its perceptual characteristics.

At 1210, the video encoder characterizes one or more portions of a videopicture. For example, the encoder characterizes a block of the videopicture based on intensity variance within the block. In oneimplementation, the encoder computes a sum of the differences between apixel and its adjacent pixels for the pixels in the block or adown-sampled version of the block. This sum of differences valuemeasures intensity variance between a pixel and its surrounding pixels.For example, surrounding pixels comprise two or more other pixelsadjacent to or nearly adjacent to a pixel, such as above or below, tothe left or right, or diagonal to a pixel. The difference between apixel's intensity and the intensities of its surrounding pixels iscomputed based on differences in luma and/or chroma data. In otherwords, the differences are computed with luma samples and/or chromasamples. An average computed difference value is assigned to the pixel(e.g., a pixel gradient). A difference value is computed in this way forpixels in a block (e.g., a block gradient), or for some sub-sampled setthereof. The difference values assigned to pixels in a block areevaluated to determine a characterization or classification (e.g.,smooth, edge, or texture; texture or non-texture; smooth or non-smooth;etc.) for the block, which can be expressed a block value. In oneexample, the pixel gradients for pixels in a block are evaluated todetermine a median difference value for the block gradient (e.g., ablock median). Thus, intensity differences between pixels within a blockprovide a measure of intensity variance for a block, macroblock, orother video picture region.

A block median is not required to determine a block value. An intensityvariance or block characterization may also be based on an average valuefor difference values assigned to pixels in the block (e.g., a blockaverage). The block median or average can be used to classify the blockand/or can be used as input to a finer-grained control function. Thecharacterization or control function adaptively varies one or moreaspects of encoding.

Alternatively, instead of computing an intensity variance tocharacterize a block, the encoder uses another metric.

At 1220, the encoder adaptively encodes the video picture based on thecharacterizations. In one implementation, encoding techniques forremoval or reduction of contouring artifacts are performed based onblock characterization. For example, gradient slope detection, DC shiftdetection, AC coefficient preservation, and adaptive differentialquantization are performed for certain smooth regions, and texturedregions are quantized more strongly to conserve bit rate.

Although FIG. 12 shows the characterizing stage 1210 preceding theadaptive encoding stage 1220 for multiple portions of a picture, thesestages may also occur iteratively on a block-by-block basis in thepicture or be ordered on some other basis.

At 1230, the encoder signals the adaptively encoded bit stream. Whendifferential quantization is used by the encoder to encode based onblock characterization, for example, the video encoder encodesinformation in the compressed bit stream using a signaling scheme forsignaling the differential quantization to a video decoder.

At 1240, a corresponding video decoder reads the adaptively encoded bitstream, including the encoded data for the video picture. For example,the video decoder reads signaled differential quantization information.At 1250, the decoder decodes the compressed bit stream, for example,dequantizing blocks according to signaled differential quantizationinformation.

A. Example Block-based Characterization

FIG. 13 is a diagram showing block-based operations for characterizingblocks using luma and/or chroma data. The luma block “Y” (1302) is an8×8 block of a macroblock in a 4:2:0 macroblock format. Although notrequired, in this example, corresponding chroma blocks 1304, 1306 forthe pixel block are also used in computing a gradient block 1308.Although not required, as shown in this example, the luma block 1302 isdown-sampled 1312 by a factor of 2 horizontally and vertically (e.g., bysimple averaging of pairs of samples) to create a luma block 1310 thatmatches the 4×4 dimensions of the chroma blocks.

As shown in the down-sampled luma block 1310, the intensity value of aluma sample for a pixel 1314 is compared to samples for four pixels nearit in the down-sampled luma block 1310, and an average sum of thedifference between the sample for the pixel 1314 and the samples for itssurrounding vertical and horizontal pixels is computed. In this example,the pixel 1314 is located at position Y′(r, c). The average sum of thedifferences for the luma intensity value for this pixel 1314 as comparedto its surrounding pixels is:L ₁(r, c)=[|Y′(r, c)−Y′(r, c−1)|+|Y′(r, c)−Y′(r−1, c)|+|Y′(r, c)−Y′(r,c+1)|+|Y′(r, c)−Y(r+1, c)|]/4  (5)

As shown, Y′(r, c) is the luma component of the pixel 1314 at row r andcolumn c in the down-sampled block Y′. L_(I)(r, c) provides anindication of how the pixel 1314 differs in luma intensity from itsneighbors within the block Y′. This luma intensity differencemeasurement is an example of a pixel gradient.

Optionally, chroma data 1304, 1306 may be considered alone instead ofluma data, or may be considered together with luma data to determineintensity differences. The average sum of the differences for lumaintensity values and chroma intensity values for pixel 1314 can berepresented as the average of the differences in intensity values ofsamples for the surrounding pixels as shown in the following equation:G _(I)(r, c)={[|Y′(r, c)−Y′(r, c−1)|+|Y′(r, c)−Y′(r−1, c)|+|Y′(r,c)−Y′(r, c+1)|+|Y′(r, c)−Y′(r+1, c)|]+[|U(r, c)−U(r, c−1)|+|U(r,c)|U(r−1, c)|+|U(r, c)|U(r, c+1)|+|U(r, c)−U(r+1, c)|]+[|V(r, c)−V(r,c−1)|+|V(r, c)−V(r−1, c)|+|V(r, c)−V(r, c+1)|+|V(r, c)−V(r+1,c)|]}/12  (6)

G_(I)(r, c) is an example of a pixel gradient for the pixel located at(r, c) in the down-sampled block, and the pixel gradient provides anindication of how the pixel 1314 differs in luma and chroma intensityfrom its surrounding pixel neighbors. In this example, the pixelgradient value G_(I)(r, c) is based on pixels that are immediatelyvertical or horizontal, but does not consider other pixels in theneighborhood. It is contemplated that other pixel data may also beconsidered in creation of a pixel gradient in other variations. Forexample, diagonal pixels could be considered as part of, or instead ofthe provided arrangement. Or, intensity differences across a longerstretch (e.g., 2 or 3 pixels) could be considered.

G_(I)(r, c) provides an indication of how a single pixel differs fromits neighbors in luma and chroma intensity. In order to characterize theintensity variance for an entire block, the same analysis is performedon plural or all pixels within the block. In one such example, a block1308 of pixel gradients is created, and a block gradient is derivedtherefrom. As noted, computing a pixel gradient or a block gradient mayinclude luma comparisons alone, chroma comparisons alone, or both lumaand chroma comparisons together.

If desirable, the above equation for finding G_(I)(r, c) may be variedto account for missing block boundary values. For example, samplesoutside the block may be extrapolated or assumed to be the same as otheradjacent samples within the block when adapting the equation G_(I)(r, c)to account for boundary values. Or, the denominator of the equations maybe reduced and surrounding samples in certain directions ignored in thecomparisons, for example, where those surrounding samples are outside ofthe block. As shown, a block 1308 of pixel gradients may provide pixelgradient data for all pixels in the block. Or, a block 1308 of pixelgradients may include pixel gradient data for less than all pixels inthe block.

FIG. 14 is a histogram of plural pixel gradients in the block 1308 ofFIG. 13. More specifically, the histogram 1400 provides a visualizationof how the block is characterized or valued. In this example, there areeight pixel gradient values below 30, and eight pixel gradient valuesabove 30. Thus, a median value for this block gradient is 30. (For aneven number of candidates, the median can be computed as the average ofthe two middle candidate values, or as one or the other of the twomiddle candidate values.) The median value may be used to characterizethe block as smooth, texture, or edge. Of course, other metrics may beused to characterize blocks once the pixel gradients or blocks of pixelgradients are obtained. For example, blocks may be characterizedaccording to an average of pixel gradient values. Once a block value isassigned it can be used in a characterization scheme (e.g., smooth ornon-smooth; smooth, texture, edge; etc.) or in a finer grained controlfunction. The block value can be used to determine how the block istreated in an adaptive encoding strategy.

A block value may be selected by ordering plural pixel gradients andselecting a median gradient value from the ordered values. For example,a set of pixel gradients within a block, such as {10, 14, 28, 36, 38},has a block value assigned equal to the median pixel gradient in theset, or 28. In another example, a block value is determined based on theaverage gradient in the set, or 25.2 for the preceding numericalexample. Of course, the set may be obtained from a complete blockgradient, or a subset thereof.

C. Example Use of Characterization Information

FIG. 15 is a graph of an example block characterization framework,continuing the example of FIGS. 13 and 14. As shown, a block with ablock value in the range from 0 up to and including 30 will becharacterized as a smooth block. A block with a block value in the rangeof greater than 30 but less than or equal to 60 will be characterized asa texture block, and a block with a block value greater than 60 will becharacterized as an edge block.

Alternatively, an encoder uses another characterization framework, forexample, one including other and/or additional characterizations forblocks or other portions of video pictures. For different gradients andmetrics, the framework can change in scale and/or number of dimensions.

An encoder can use the characterizations of the blocks or other portionsof video pictures when making encoding decisions. Table 2 relatesfeatures of an example adaptive coding scheme to block characterizationsas described with reference to FIG. 15. As shown, differentlycharacterized blocks are treated differently in terms of one or moreadaptive features.

TABLE 2 Adaptive Encoding Features Gradient Slope Characterization DCShift Detection Detection Quantization Smooth Yes Yes Lower QP Edge NoNo Higher QP Texture No No Higher QP

The various adaptive features shown in Table 2 are discussed throughoutthis document and will be further discussed below. Alternatively, anencoder uses another mapping of adaptive feature decisions to blockcharacterizations. Moreover, some features described herein need nottake into account characterizations of video content.

IV. Differential Quantization Based on Texture Level

In differential quantization, an encoder varies quantization step sizes(also referred to herein as quantization parameters or QPs in someimplementations) for different parts of a picture. Typically, thisinvolves varying QPs on a macroblock or other sub-picture level. Anencoder makes decisions on how to vary the QPs and can signal thosedecisions, as appropriate, to a decoder.

Previous encoders have used bi-level differential quantization (varyingbetween two QPs) and multi-level differential quantization (varyingbetween three or more QPs). For example, in one bi-level differentialquantization approach, one QP is used for macroblocks at picture edgesand another QP is used for macroblocks in the rest of the picture. Thiscan be useful for saving bits at picture edges, where fine detail isless important for maintaining overall visual quality. In a multi-leveldifferential quantization approach, a larger number of different QPs canbe used for individual macroblocks in a picture. For example, an encodercan choose a QP for a macroblock and signal a differential between theQP for the current picture and the QP for the macroblock.

Perceptual sensitivity to quantization artifacts is highly related tothe texture level of the video in both the spatial and temporal domain.High texture levels often result in masking effects that can hidequality degradation and quantization artifacts. However, in regions withlower texture levels (e.g., smooth regions), degradation andquantization artifacts are more visible. Although previous encoders havemade quantization adjustments for some parts of video pictures (e.g.,picture edges), a more comprehensive content-based differentialquantization strategy as described herein provides improvedrate-distortion performance in many scenarios.

Accordingly, many of the described techniques and tools usetexture-based differential quantization (referred to herein as textureDQ) to allocate bits based on various texture levels to achieve betterperceptual quality. In texture DQ, different QPs are chosen to codevideo based on texture information and, in some cases, based on otherinformation such as temporal analysis information. An encoder analyzestexture information (and possibly other information) and applies textureDQ to appropriate regions (texture DQ regions), such as 8×8 blocks ormacroblocks in a picture. Many of the described techniques and toolsfocus on smooth regions as potential texture DQ regions. Smooth regionsinclude flat regions (areas of constant or nearly constant color) andgradient slope regions (areas of color that vary at a constant or nearlyconstant rate across the region). Smooth regions may be consideredsmooth even when interrupted by small areas of noise, film grains, orother color variations.

FIG. 16 is a flow chart showing a generalized technique 1600 forapplying differential quantization based on texture information. Anencoder such as the encoder 1000 of FIG. 10 or other tool performs thetechnique 1600.

At 1610, an encoder obtains texture information (e.g., characterizationsor block values that indicate whether different regions are smooth,edge, or texture regions) for a current picture. At 1620, the encoderfinds a texture DQ region (e.g., a smooth region in which contouringartifacts may be present) or texture DQ regions in the current picture.At 1630, the encoder applies texture DQ to the texture DQ region(s) andencodes the picture. For example, smooth regions are coded with smallerQPs than high texture regions. If there are more pictures to encode, theencoder takes the next picture at 1640 and selectively applies textureDQ to the next picture, as appropriate. The encoder outputs encoded datafor the video picture, for example, to storage, a communicationconnection, or a buffer.

Different texture DQ region detection techniques can be used todetermine whether a region should be treated as a smooth region. Forexample, an encoder can use different texture metrics and/or differenttexture thresholds (and can adjust thresholds adaptively) to determinewhether a particular region should be considered a texture DQ region.Adaptive quantization value mapping can be used to allocate bits forbetter perceptual video quality. Differential quantization decisionsalso can be based on temporal analysis (i.e., looking at future picturesto make decisions based on characteristics of a region over time).

Differential quantization decisions can be made for both intra picturesand predicted pictures. For predicted pictures, P- and B-picturedifferential quantization intervals between differentially quantizedpictures can be controlled. Further, by observing the texture of apicture when dominant high texture areas are present, the smooth regiontexture threshold can be relaxed to code a relatively smooth region(compared to the dominant high texture areas) with a smaller QP.

Techniques similar to those described with reference to FIGS. 12-15 inSection III, above, can be used to generate a texture map for a currentpicture. For example, the encoder calculates gradients for the texturelevels for the picture as the first derivatives (differences) in the Y,U and V channels for the picture, as described in section III. When themacroblock format is 4:2:0, to speed up the calculation process, theencoder can downsample the Y channel by a factor of 2:1 horizontally andvertically. The encoder sums the gradients of Y, U and V for each pixelin both horizontal and vertical direction. For an 8×8 block in fullresolution, the encoder computes the mean of the sum of the gradients inthe corresponding 4×4 block in the downsampled picture to use as theblock gradient value. Computing the mean of the gradients has a lowercomputational complexity than computing the median as described insection III.

Alternatively, an encoder obtains texture information for the picture insome other way. For example, an encoder chooses different gradientdirections for calculating gradients, calculates gradients only for theluma channel, etc. However the texture information is obtained orcalculated, it can then be used to make texture DQ decisions.

The texture map indicates the texture levels of the different parts ofthe picture. For example, the texture map can be used to identify smoothregions (e.g., blocks, macroblocks, edges, or other areas) and texturedregions in the picture. Described differential quantization techniquescan be performed on appropriate parts of the picture based on theinformation in the texture map. Alternatively, an encoder use textureinformation without first creating a texture map.

A. Temporal Analysis

In addition to texture information from a current video picture,temporal analysis can be used to make accurate differential quantizationdecisions. One reason for using temporal analysis is that the impact ofusing a smaller QP on a smooth region will be greater if the smoothregion remains smooth over several pictures, especially when the otherpictures reference the smooth region in motion compensation. Conversely,one benefit of using a smaller QP will be lost if smooth blocks arereplaced with high texture or edge blocks in future pictures.Accordingly, an encoder looks at future pictures after finding a smoothregion in a current picture and makes differential quantizationdecisions based on how smoothness of the region changes in the futurepictures. The encoder can also look at previous pictures, for example,B-pictures that precede a current video picture in display order butreference the current video picture in motion compensation.

FIG. 17 shows an example technique 1700 for using temporal analysis tomake texture DQ decisions. An encoder such as the encoder 1000 of FIG.10 or other tool performs the technique 1700.

At 1710, an encoder performs texture analysis on a current block in acurrent picture in a video sequence. For example, the encoder looks atgradient information for the block. The encoder can compare the gradientinformation to a gradient threshold for the block and classify the blockas smooth or non-smooth (e.g., texture, edge), where the gradientthreshold is fixed or set dynamically for the current picture or otherpart of the video sequence. Alternatively, the encoder performs textureanalysis for some other portion in the current picture.

At 1720, the encoder performs temporal analysis. The encoder can performthe temporal analysis automatically or only if the current block isclassified as a smooth block. For example, the encoder determines if asmooth block in a current picture stays smooth in future pictures. Ifso, the smooth region in the current picture is later coded with asmaller QP. Or, the encoder determines if a smooth block in the currentpicture was also smooth in previous pictures, or in both previous andfuture pictures.

The number of previous and/or future pictures that the encoder analyzescan vary depending on implementation. If the smooth region is replacedin a future picture (e.g., the next picture or some other temporallyclose picture) by a textured region, the smooth region in the currentpicture might be coded with a larger QP, since the advantages of using asmaller QP are likely not as persistent. In one implementation,temporally closer pictures are weighted more heavily than more distantpictures in making the differential quantization decision. The weightingand the number of previous and/or future pictures that the encoder looksat can vary depending on implementation.

To simplify the calculations, the encoder can find a single value tocompare the current block and the corresponding block in a futurepicture. For example, since luma values are fairly consistent withinsmooth blocks, the mean of the luma values for the block is calculatedto measure the similarity of corresponding blocks in future pictures. Inthe following example equation, the “strength” S(t) of the futuresmoothness of corresponding blocks in a future picture is calculated bya sum of the weighted absolute difference between the mean luma valuesof the current block and the corresponding block in the future picture,the mean luma values of the corresponding blocks in the two futurepictures, and so on.

$\begin{matrix}{{S(t)} = {{C(n)}*{\sum\limits_{i = 1}^{n}{\left( {n - i + 1} \right)*{\left( {{M\left( {t + i} \right)} - {M\left( {t + i - 1} \right)}} \right.}}}}} & (7)\end{matrix}$where n is the total number of temporal “look-ahead” pictures, C(n) isnormalization factor, which is defined to be 2/(n*(n+1)), and M(t) isthe mean of luma values for the block (or corresponding block) in thepicture at time t. The encoder can also measure past smoothness insteadof or in addition to future smoothness. Alternatively, the encoder usesanother weighting system and/or smoothness metric in the temporalanalysis of smoothness.

Referring again to FIG. 17, at 1730 the encoder uses results of thetexture analysis and the temporal analysis to determine whether toclassify the block as a texture DQ block. For example, the encodercomputes a smoothness strength S(t) for a smooth block (but not otherblocks) and compares the smoothness strength S(t) to a temporalsmoothness threshold. The temporal smoothness threshold can be fixed ordynamically set.

In FIG. 17, if the encoder finds that the current block is a smoothblock and that the corresponding block in previous and/or futurepictures is also smooth, the encoder adds the current block to a countof texture DQ blocks at 1740. The encoder can use the count of textureDQ blocks to determine whether to perform texture DQ on the picture.Alternatively, an encoder uses temporal analysis in some other way tomake a texture DQ decision.

If there are more blocks to analyze, the encoder takes the next block at1750 and repeats the process shown in FIG. 17. This continues until theencoder has evaluated the blocks of the current video picture. At thatpoint, the encoder uses the count of smooth blocks or other results ofthe temporal analysis in an encoding decision.

Although FIG. 17 shows an encoder performing temporal analysis on ablock-by-block, alternatively, the encoder performs temporal analysis ona macroblock-by-macroblock basis or some other region-by-region basis.

B. Texture IDQ Thresholds and Isolated Smooth Block Filtering

Whether or not the encoder uses temporal analysis, the encoder can useseveral other mechanisms in deciding when to apply texture DQ. Anencoder can use one or more prevalence thresholds (e.g., percentages ofsmooth blocks in the picture) to make decisions on whether to perform DQand, if so, how fine the QPs for texture DQ regions should be. Forexample, if the number or percentage of smooth blocks in a picture isabove a threshold, the encoder can choose a coarser step size in orderto avoid spending too many bits encoding smooth content with small QPs.The encoder also may have a lower threshold to determine whether thenumber or percentage of smooth blocks is enough to use texture DQ in thepicture at all.

Another way to reduce bit rate is to treat certain smooth blocks astexture blocks when the smooth blocks are in predominantly texturedregions. This can be referred to as isolated smooth block filtering(although a smooth block need not be completely “isolated” to befiltered in this way). For example, a smooth block surrounded bytextured blocks need not be coded with a smaller QP than the texturedblocks, since quantization artifacts in the smooth block are likely tobe masked by the surrounding textured content. As a result, an encodercan choose not to perform texture DQ on isolated smooth blocks. Theencoder also can disregard isolated smooth blocks when calculating thenumber or percentage of smooth blocks in a picture.

FIG. 18 shows an example technique 1800 for making a texture DQ decisionusing thresholds and isolated smooth block filtering. An encoder such asthe encoder 1000 of FIG. 10 or other tool performs the technique 1800.

At 1810, the encoder finds smooth blocks in the current picture. Forexample, the encoder performs texture analysis and temporal analysis asdescribed with reference to FIG. 17. Alternatively, the encoder findsthe smooth blocks in the current picture in some other way.

At 1820, the encoder performs isolated smooth block filtering. Forexample, the encoder removes single smooth blocks that are surrounded inthe current picture by non-smooth blocks. An encoder can use manydifferent decision models to perform isolated smooth block filtering.For example, an encoder can choose to treat a smooth block as a texturedblock only when all its neighboring blocks are textured blocks. Or, anencoder can choose to treat a smooth block as a textured block if acertain number of its neighboring blocks are textured. Or, the encoderremoves isolated smooth blocks in larger groups (e.g., 2 or 3) and/orusing some other test for whether block(s) are isolated.

At 1830, the encoder checks the percentage of smooth blocks in thepicture against a low threshold (e.g., 1-2% of the total blocks in thepicture). If the percentage of smooth blocks falls below the lowthreshold, the encoder determines that texture DQ will not be used forthis picture (1840). If the percentage of smooth blocks is above the lowthreshold, the encoder checks the percentage against a high threshold at1850. This higher threshold is used to pick a QP for the smooth blocks.If the percentage is higher than the high threshold, the encoderperforms texture DQ but chooses a coarser QP (1860) for the smoothblocks to reduce bit rate. Otherwise, the encoder chooses a finer QP(1870) for the smooth blocks. If there are more pictures to analyze(1880), the encoder can repeat the process for other pictures. Thenumber of thresholds and the threshold percentage values can varydepending on implementation.

Alternatively, an encoder performs isolated smooth block filteringwithout using texture DQ thresholds, or uses texture DQ thresholdswithout isolated smooth block filtering. Or, an encoder performs textureDQ without isolated smooth block filtering or using DQ thresholds.

C. Adaptive Texture Level Threshold

An encoder can use a fixed texture-level or smoothness threshold todetermine whether a given block should be considered a texture DQ block(e.g., a smooth block). Taking into account the bit rate cost of DQsignaling (e.g., one bit per macroblock in an “all macroblock” bi-levelDQ signaling scenario) and the bit rate cost of quantizing some parts ofa picture at a smaller QP, the threshold acts as a check on the costs oftexture DQ. For example, an encoder obtains a block value (using atechnique described with reference to FIGS. 13 and 14 or some othertechnique) for a block and compares the block value to a fixedtexture-level/smoothness threshold value (e.g., a threshold valuedescribed with reference to FIG. 15).

An encoder also can adaptively change texture-level/smoothness thresholdvalues. For example, since the perceptibility of smooth blocks maychange in pictures with a lot of high-texture content, the texture-levelthreshold for classifying a block as a smooth block can be relaxed in amedium-texture or high-texture picture. This is an example of anadaptive texture-level threshold. An encoder may allow several differentthresholds to be selected within a range of thresholds. In oneimplementation, an adaptive texture-level threshold for smooth blockscan be varied between a block value of 14 and a block value of 30.Different differential quantization mappings can be used for differenttexture-level thresholds. An adaptive texture level threshold can beuseful for allocating bits to smoother regions in higher-texture framesto improve quality in the smoother regions.

FIG. 19 shows a technique 19 for selectively adjusting texture levelthresholds for high-texture pictures. An encoder such as the encoder1000 of FIG. 10 or other tool performs the technique 1900. The encoderdetermines whether to adjust texture level thresholds by detecting thepresence of dominant high-texture content in a picture. In oneimplementation, the detection of high-texture content is implemented bycalculating the texture “energy” in a sliding window with size of 10 ina texture histogram.

Referring to FIG. 19, an encoder obtains a texture information (e.g., atexture level histogram) for a picture at 1910 in an adaptivetexture-level threshold technique 1900. For example, the encoder obtainsa texture map as described above and creates a texture level histogramfrom the information.

At 1920, the encoder checks whether the picture is a high-texturepicture. If the picture is a high-texture picture, the encoder adjuststhe texture level threshold for the picture at 1930. If the picture isnot a high-texture picture, the encoder processes the picture withoutadjusting the texture level threshold (1940). The encoder then cananalyze and choose texture level thresholds for other pictures (1950).Alternatively, the encoder applies a sliding scale of different texturelevel thresholds for different levels of high-texture content in thepicture.

For example, to check the extent of dominant high-texture content in apicture, an encoder computes a texture histogram for the picture. Theencoder applies a sliding window in the texture histogram to calculatetexture energy and determine a peak or prominent high-texture band.Equation (8) shows one way for the encoder to calculate the textureenergy in the window. The sliding window starts sliding from the minimumtexture level threshold g0 (which is by default 30), and the encodercomputes the window value W(g) at g0. The sliding window shifts 1 to theright after calculation of texture energy for that window, and theencoder computes the next window value W(g) starting at the new value ofg0. This continues until the encoder reaches the maximum of the texturelevels represented in the histogram.

Let F(g) be the histogram of texture level per pixel. Let E(g) be thetexture energy for the texture level, where E(g)=F(g)*g. The encodercalculates the texture energy of the sliding window W(g) as follows:

$\begin{matrix}{{W(g)} = {\sum\limits_{g = {g\; 0}}^{{g\; 0} + 10}{\left( {{F(g)}*g} \right).}}} & (8)\end{matrix}$

If the maximum sliding window energy W(g) exceeds a certain percentagethreshold of overall picture energy, g0 for that maximum sliding windowenergy W(g) is used to adjust the threshold for smooth regions.

FIG. 20 shows pseudo-code 2000 used to determine a new adaptive smoothregion threshold from g0. If g0 is over 100, the adaptive threshold isset to 30. The encoder also checks if g0 is less than 30 and, if so,sets the adaptive threshold to 14. Otherwise, if 30≦g0<100, the adaptivethreshold is set to a value from the table g_iFlatThTable. To helpmaintain video quality, the maximum difference of a new adaptivethreshold from the last adaptive threshold is capped at +/−4 for allpictures except scene change key pictures. The adaptive smooth thresholdshould not exceed the threshold used to identify textured blocks—forexample, in FIG. 20 the highest adaptive threshold value is 30.

Alternatively, an encoder adaptively adjusts texture level thresholds insome other way (e.g., with a different texture strength or energymetric, without a sliding window, with a differently configured slidingwindow, with different threshold values in a table or other datastructure, without capping differences between adaptive thresholds,capping differences in adaptive thresholds in some other way, etc.).

D. I-Picture and P-Picture Differential Quantization

Described differential quantization techniques and tools can be usedseparately or in combination on intra pictures and predicted pictures.The term I-picture differential quantization (I-picture DQ) refers toapplication of differential quantization to I-pictures, and the termP-picture differential quantization (P-picture DQ) refers to applicationof differential quantization to P-pictures. The use of I-picture DQresults in higher quality I-pictures, and the quality improvement can bemaintained longer for predicted pictures that depend from thoseI-pictures. P-picture DQ can further improve P-picture quality in bothintra and inter blocks, but the quality of those P-pictures will alsodepend on the quality of the pictures from which they are predicted.Similarly, the impact of P-picture DQ on the quality of later predictedpictures will depend the similarity of the later predicted pictures tothe pictures from which they are predicted.

E. Differential Quantization Intervals

Both I-picture DQ and P-picture DQ use one or more of the techniquesdescribed herein to decide whether to apply different QPs for differenttexture-level blocks. To balance quality and bit usage, a P-picture DQinterval can be used to control the amount of bits that are spent onP-picture DQ. For example, an encoder chooses to use P-picture DQ on onein every n P-pictures, where n≧1, but skips P-picture DQ for pictures inthe interval between differentially quantized P-pictures. The encoderspends bits on differential quantization to improve the perceptualquality of some P-pictures, and those quality improvements carry overinto other predicted pictures. At the same time, the DQ interval helpsconstrain the overall number of bits the encoder spends on differentialquantization of predicted pictures.

Alternatively, the encoder selects another interval. For example, theencoder may choose to use P-picture DQ on only one P-picture perI-picture, or choose some other interval. The interval may be fixed oradaptive. For example, the encoder may adaptively adjust the P-pictureDQ interval based on the type of content being encoded.

V. Gradient Slope Detection

Among various visual artifacts introduced in video compression,contouring is one particular artifact that can be caused byquantization. Contouring artifacts are perceived by human eyes asstructured, gradient discontinuities in what are otherwise continuous,very smooth regions such as sky, water, etc. Such discontinuities can bevery distracting and may lead a human observer to conclude that a wholepicture is badly distorted even if other parts of the picture are codedwith little visual distortion.

Gradient slope regions can give rise to contouring artifacts. Accordingto one definition, a region is considered to be a gradient slope regionif the region is smooth or relatively smooth but pixel values changegradually within the region. Thus, while both gradient slope regions andflat regions are considered to be smooth regions, gradient slope regionsdiffer from flat regions. According to one definition, a flat region ischaracterized by constant or relatively constant pixel values throughoutthe flat region. Gradient slope regions typically lack strong edges andextensive texture detail.

FIG. 21 shows two examples of gradient slope regions. The gradient slopedirection in each region is represented by arrows. In gradient sloperegion 2100, luma values increase gradually from the top to the bottomof the region. The direction of the slope in gradient slope region 2100is the same in each part of the region. In gradient slope region 2110,luma values increase gradually from the center to the edges of theregion. The direction of the gradient slope varies within the gradientslope region 2110. However, within small neighborhoods, the gradientslope direction at each point is within a small angle θ of the gradientslope direction at other points in the neighborhood, except for theneighborhood that includes the center point. As shown in FIG. 21,gradient slope regions include regions where the gradient slopedirection is constant throughout the region, and regions where thegradient slope direction has small variations within a neighborhood.

FIG. 22A is a diagram showing an example picture 2200 with a gradientslope region 2210, a textured region 2220, a sharp-edge region 2230 anda flat region 2240. FIG. 22B is a diagram showing results ofquantization in the gradient slope region 2210. The banding effect thatis now visible (e.g., within macroblock 2250) is a contour artifact.FIG. 22C shows detail of the macroblock 2250. Quantization of transformcoefficients for the top half of the luma samples in macroblock 2250results in uniform values stemming from a DC value of 68. Quantizationof transform coefficients for the bottom half of the luma samples inmacroblock 2250 results in uniform values stemming from the DC value of70. Thus, the quantization of the transform coefficients for the lumasamples has created a visible contour artifact between the top-half 8×8blocks and the bottom-half 8×8 blocks in macroblock 2250.

Many existing video encoders use techniques that are applied to a wholevideo picture in an attempt to reduce contouring artifacts in thepicture. Such techniques may result in over-spending bits, especially inregions that contain little or no contouring artifacts. Accordingly,several described techniques and tools allow an encoder to detectgradient slope regions, where contouring artifacts are likely to happen.When gradient slope regions are detected, an encoder can make codingdecisions that reduce or avoid introduction of contouring artifacts(e.g., adjustments of QPs) in the gradient slope regions. By doing so,an encoder can allocate bits more effectively and achieve better visualquality.

To detect gradient slope regions, an encoder can implement one or moreof the following techniques:

-   -   1. Gradient slope region detection with coding decisions focused        on reducing or removing introduction of contouring artifacts in        the detected region(s).    -   2. Region-based gradient estimation and down-sampling to reduce        computational cost and/or allow accurate gradient slope region        detection despite the presence of anomalies such as film grains.    -   3. A gradient consistency check to detect gradual gradient        change in local neighborhoods.    -   4. Bucket voting to make a binary decision regarding the        presence of gradient slope region(s) in a picture.    -   5. The generation of a gradient slope mask (e.g., at        macroblock-level) and gradient direction map to help an encoder        to make appropriate coding decisions.

FIG. 23 shows a generalized region-based gradient slope detectiontechnique 2300. An encoder such as the encoder 1000 of FIG. 10 or othertool performs the technique 2300. In some cases, the region-basedgradient slope detection technique 2300 allows faster detection ofgradient slope content by eliminating the need to find gradient slopedirections for each pixel in a picture. For example, the picture isdivided into non-overlapping rectangular regions of the same size. Thesize of the regions can vary depending on implementation. In oneimplementation, a region is a 16×16 macroblock (four 8×8 blocks).Preferably, the region is of a size that allows macroblock alignment.

At 2310, an encoder checks whether a current region is a smooth region.For example, the encoder uses a texture map of the picture in which an8×8 block is characterized as smooth if its assigned block gradientvalue is less than 30, or the encoder uses checks whether the currentregion is smooth using another technique described in section III or IV.When a region includes multiple blocks, the region is considered to be asmooth region if all blocks contained in the region are smooth (or,alternatively, if some minimum number of the blocks are smooth).Different implementations can use different criteria for determiningwhether a particular region or block is smooth. For example, thecriteria for determining whether a region is smooth may be different ifthe picture is down-sampled.

If a region is not smooth, the next region is processed (2320). For asmooth region, the encoder finds a gradient direction at 2330. Forexample, the encoder finds a gradient direction using a technique suchas the one described with reference to FIGS. 26 and 27. Alternatively,the encoder finds the gradient direction with some other technique.

At 2340, the encoder makes a gradient slope decision for the region,using thresholds and/or decision-making logic that depend on thetechnique and metrics used to find the gradient direction for theregion. If there are more regions to be processed, the encoder processesthe next region (2320). In one implementation, after computing initialgradient directions for different regions in a picture, the encodergenerates a binary mask that indicates whether gradient slope is presentin different regions by applying a sliding window in the picture. Theinformation in the binary mask allows the encoder to make accurategradient slope decisions.

FIG. 24 is a block diagram of an example gradient slope region detector(GSR detector) 2400 in a video encoder such as the one shown in FIG. 10.The GSR detector 2400 takes pixel data from a current picture 2405 asinput.

Depending on picture size and potentially other factors, the GSRdetector 2400 determines whether to perform down-sampling indown-sampling module 2410. Example down-sampling techniques aredescribed below.

The gradient calculator 2420 takes (possibly down-sampled) pixel dataand a texture map 2425 as input and calculates gradients for smoothregions. For example, the gradient calculator uses a technique such asthe one described with reference to FIGS. 26 and 27 or uses some othertechnique. An example region size in the gradient calculation is 16×16,but the size of regions can vary depending on implementation. Dependingon whether and how much down-sampling is applied, the region for which agradient is calculated can represent different amounts of area in theoriginal picture 2405. The gradient calculator 2420 outputs a map orother data structure indicating the gradient directions for smoothregions.

The consistency checker 2430 takes the calculated gradients for smoothregions and checks the angular consistency of those gradients, forexample, as described below. The consistency checker 24 produces aconsistency map or other data structure indicating consistencyinformation for the calculated gradients.

The decision module 2440 uses additional decision rules (afterconsistency checking) to determine whether smooth regions should beconsidered gradient slope regions. Example decision rules and criteriaare described below. The decision module 2440 considers the consistencymap or other data structure indicating consistency information, and canalso consider the calculated gradient directions or other information.The decision module 2440 outputs decision information in a map or otherdata structure for regions of the same or different size than the regionsize used in the gradient calculation.

The decision for each region is provided to mask generator 2450 whichproduces a gradient slope mask and/or a binary gradient slope decisionmask 2495 that indicates gradient slope decisions for regions in thepicture. For example, a mask 2495 comprises a bit equal to “1” for eachgradient slope region and a bit equal to “0” for other regions.Accepting calculated gradients as input, the mask generator 2450 canproduce another mask 2495 that indicates final gradient slopes fordifferent regions of the original picture, accounting for down-samplingand mask decisions. When the GSR detector 2400 performs down-samplingbefore gradient calculation, the mask generator 2450 can assign gradientslopes for down-sampled regions to corresponding regions of the originalpicture.

The components of the GSR detector 2400 are shown as separate modules inFIG. 24, but the functions of these components can be rearranged,combined or split into different modules depending on implementation.Furthermore, components of gradient slop detector 2400 can be omitted inother implementations. For example, down-sampling is not required. A GSRdetector need not take a texture map as input, and can instead get anindication of whether a region is smooth or not from some other source.A GSR detector need not use a consistency checker. Although a GSRdetector will make some kind of decision as to whether a region is agradient slope region, the specifics of how decisions are made(including decision rules in the decision module) can vary dependingimplementation. Gradient slope decisions need not be included in abinary mask and may be communicated to other parts of the encoder insome other way.

A. Region-based Gradient Direction Estimation with Down-sampling

Down-sampling can be used prior to finding gradient directions forregions in order to reduce computational cost. In one implementation, ifthe original picture width is greater than 1280 and the height isgreater than 720, the original picture is 4-to-1 down-sampled. Forexample, in a 1080 p arrangement with a picture width of 1920 pixels anda picture height of 1080 pixels, a decoder produces a down-sampledpicture with a width of 480 pixels and a height of 270 pixels.

Typically, a down-sampled picture is divided into non-overlappingrectangular regions of the same size. For example, after downsampling,each 16×16 region corresponds to 4 macroblocks (16 blocks) of theoriginal, full resolution picture. A region in the down-sampled pictureis considered to be a smooth region if at least 12 blocks to which theregion corresponds are smooth. Region sizes depend on implementation,and the relation between regions in gradient estimation and regions inoriginal pictures varies depending on down-sampling ratio.

Down-sampling also is useful for improving accuracy of gradient sloperegion detection despite the presence of anomalies such as film grains.For example, consider a portion of a picture 2500 with DC values ofblocks as shown in FIG. 25. The majority of the picture portion 2500 hasconsistent gradient slope directions, as shown by the graduallyincreasing DC values from the top to the bottom of the picture portion.However, the white sample values represent DC values affected by filmgrains that create anomalous gradient slope directions at fullresolution. With simple 2-to-1 down-sampling horizontally andvertically, the dark-bordered sample values are used to calculate thegradient slope direction. Because the down-sampled values maintain aconsistent gradient slope, the film grains do not affect detection ofthe gradient slope.

Down-sampling can be used for other picture resolutions, and otherdown-sampling ratios also can be used.

B. Calculating Gradient Slope Direction

In one implementation, to calculate gradient slope direction for asmooth region, two 16×16 compass operators K_(H) and K_(V) (defined inFIG. 26) are applied to the region. This produces two gradients g_(x),g_(y) for the region, one for the horizontal direction and one for thevertical direction. For a 16×16 region, the compass operators givepositive weights to some values of the region and negative weight toother values of the region. Alternatively, the compass operators computegradients in some other way.

An angular representation of the gradient direction, denoted as θ, isderived from the two gradients and mapped to an integer in [0, 255]. Thepseudo-code 2700 in FIG. 27 shows an example routing for computing thegradient direction for a region ({circle around (X)} denotes aper-element product) using the compass operators of FIG. 26. If theregion is a textured region or edge region, the routine returns −2. Ifthe region is smooth but flat (indicated by low absolute values for thegradients g_(x) and g_(y) for the region, the routine returns −1.Otherwise, the routine computes the gradient slope as the arctangent ofthe vertical gradient g_(y) over the horizontal gradient g_(x), usingoffsets to differentiate between slope directions for same arctangentvalues (e.g., whether a positive arctangent value indicates an above,right slope or a below, left slope) and represent the range of slopevalues as positive numbers.

Alternatively, the gradient direction is computed in some other way. Forexample, the encoder uses different compass operators, differentthresholds for slope regions, different logic to compute the slope,and/or a different representation for slope information.

C. Neighborhood Gradient Consistency Check

An encoder can perform a gradient consistency check for regions in orderto help make an accurate decision about whether a region should beconsidered a gradient slope region. The gradient consistency check helpsto avoid “false alarms” in gradient slope content detection. In oneimplementation, the gradient slope consistency check involves using a3×3 sliding window (three regions by three regions) to determinegradient slope consistency.

FIG. 28 shows a technique for performing consistency checking forgradient slope regions. An encoder such as the encoder 1000 of FIG. 10or other tool performs the technique 2800.

At 2810, the encoder positions a sliding window at a current region inthe picture. At 2820, the encoder checks the gradient directions ofregions in the sliding window. Then, at 2830, the encoder makes aconsistency decision for the current region. For example, given thegradient directions of detected smooth regions in a picture (potentiallydown-sampled), a gradient consistency check is performed with thesliding window containing 3×3 neighboring regions. The window is movedin raster scan order, positioning the window on a region in the picture(e.g., by centering the window on the region, performing the consistencycheck, then moving the window from left to right across the picture).For a given window value, the consistency check requires the differencebetween the maximum and the minimum gradientDirection (see, e.g., FIG.27) of all 9 regions within the window to be less than 32 (equivalent to45 degrees when slopes are represented by numbers from 0 to 255). Ifthis condition is satisfied, the moving window value for the 3×3 set ofregions is 1; otherwise it is 0. Alternatively, the encoder uses adifferent mechanism to check consistency of slope directions, forexample, using a different size sliding window, different slope rangethreshold for maximum slope—minimum slope, different measure such asvariance for slope consistency, and/or different checking pattern, orcomputes a sliding window value for each region as opposed to sets ofregions. The consistency check varies for different representations ofslope information.

The encoder can then process the next set of regions (2840). As output,the encoder produces a mask or other data structure indicating decisioninformation. For example, the encoder produces a binary consistency mask(referred to herein as consistencyMask) obtained by positioning thesliding window and performing the consistency check on sets of regionsin the picture, and assigning each set of regions a decision of 1(consistent slope) or 0.

Optionally, the encoder performs further processing on the decisioninformation. In some implementations, an encoder performs morphologicaloperations on a consistency mask to help refine gradient consistencydecisions for a picture. Two possible morphological operations are Erodeand Dilate.

For example, an Erode operation is performed on every bit in theconsistencyMask, followed by a Dilate operation. In the Erode operation,a bit initially marked as 1 is marked as 0 if in the four closest pixels(here, values in the consistencyMask), more than one was initiallymarked as 0. In the Dilate operation, a bit initially marked as 0 ismarked 1 if in the four closest pixels, more than one were initiallymarked as 1.

Alternatively, an encoder generates masks without using morphologicaloperations or other post-processing of the decision information.

D. Decision Rules and Bucket Voting

Even after performing consistency checking, the incidence of smoothregions may be so low, or the smooth regions may be so isolated, thatthey would be inefficient to encode specially. For example, even afterapplying morphological operations, there may still be gradient sloperegions represented in consistencyMask that are isolated enough to notneed differential quantization. In some implementations, an encoder usesdecision rules (including, for example, bucket voting) to help decidewhether DQ should be applied to gradient slope regions in the picture.In the GSR detector 2400 of FIG. 24, decision module 2440 makes suchdecisions.

In one implementation, the encoder makes one or more binary decisionsregarding whether the current picture contains significant gradientslope based on consistencyMask. The mask consistencyMask is divided into25 rectangular regions of the same size (called buckets) with 5 bucketsin each row and 5 in each column. (The “bucket” regions are hence largerthan the regions used for decisions and regions used for gradientcalculations.) The I s within each bucket are counted. Let Buckets[i][j]0 be the number of 1s contained in the bucket at location (i,j),where 0≦i,j≦4. Horizontal and vertical bucket projections—the number of1s in each column of buckets and the number of 1s in each row ofbuckets, respectively—also are calculated according to the followingrelationship:

$\begin{matrix}{{{{BucketProjection\_ H}\;\lbrack i\rbrack} = {\sum\limits_{0 \leq j \leq 4}{{{Buckets}\;\lbrack i\rbrack}\lbrack j\rbrack}}}{{{BucketProjection\_ V}\;\lbrack j\rbrack} = {\sum\limits_{0 \leq i \leq 4}{{{Buckets}\;\lbrack i\rbrack}\lbrack j\rbrack}}}} & (9)\end{matrix}$

In this implementation, the picture is considered to contain significantgradient slope if any of the following conditions are satisfied:

-   -   1. At least 6% of the pixels in consistencyMask (regardless of        bucket distribution) are marked as 1 OR    -   2. In one or more of the buckets, at least 75% of the pixels are        marked as 1, OR    -   3. In one or more of the bucket projections, at least 20% of the        pixels are marked as 1.

For example, 16×16 regions for a down-sampled picture of size 960×1440are represented with a mask of size 20×30 (each value for a 3×3 set ofregions of the down-sampled picture), which is in turn divided into 25buckets, each bucket corresponding to a 24 regions of the consistencymask. Each bucket includes 24 bits from consistencyMask, for a total of25×24=600 bits. The encoder counts the number of 1s in each bucket, witha distribution as shown in FIG. 29. The encoder checks whether the totalnumber of 1s is more than 6% of all bits. In this case, the total numberof 1s (as shown in FIG. 29) is 83, which is more than 6% of all bits.Thus, the encoder in the case would skip bucket projection, due tosatisfaction of condition 1, above. If the total number of 1s were belowthe threshold for condition 1, the encoder would whether 75% of the bitsin any bucket were 1s (condition 2), and, if necessary, check horizontaland vertical bucket projections (condition 3) to determine whether theregions indicated as being gradient slope regions are such that agradient slope mask and decision mask should be generated, such as themacroblock-level gradient slope masks described below.

Alternatively, an encoder uses other decision rules for processingconsistency information in a mask consistencyMask or otherrepresentation. For example, the percentage thresholds shown inconditions 1, 2 and 3 can vary depending on implementation. Or, one ormore of the conditions is omitted, or the conditions are reordered,replaced or supplemented by other conditions (e.g., different directionsfor bucket projections, etc.). Aside from checking consistencyinformation, the encoder can also consider gradient values and/or otherinformation when deciding whether or how much DQ should be applied togradient slope regions in the picture. As another alternative, anencoder can omit these decision rules altogether, and simply use theconsistencyMask when generating a gradient slope mask.

E. Macroblock-level Gradient Slope Mask Generation

To provide gradient slope information in a form useful for later encoderdecision-making, the encoder puts the information in maps, masks, orother data structures. The information can include gradient slope regionpresence/absence information as well as actual gradient direction valuesfor gradient slope regions.

For gradient slope presence/absence information, if gradient sloperegions are detected, the encoder produces a gradient slope mask. Forexample, an encoder produces a macroblock-level gradient slope mask(referred to herein as MBSlopeMask) by converting a region-level mask(such as consistencyMask) back to macroblock-level for the originalpicture, considering possible down-sampling. Note that each value inconsistencyMask corresponds to 9 macroblocks in the original picture, or36 macroblocks if the picture is 4-to-1 down-sampled. For each bit withvalue 1 in consistencyMask, the encoder marks corresponding macroblocksas 1 in MBSlopeMask except for macroblock that are not smooth. Checkingfor smoothness again helps to avoid false alarms in gradient slopedetection. For example, in one implementation an encoder uses a texturemap to obtain texture information for blocks in a macroblock, and themacroblock is considered smooth only if all four blocks within themacroblock are smooth.

Alternatively, the encoder provides gradient decision information insome other form and/or uses some other decision for macroblocksmoothness.

For gradient direction information, a gradient direction map isgenerated by assigning each region's gradient direction to all itscorresponding macroblocks that are smooth. In doing so, the encoderaccounts for possible size differences between macroblocks of theoriginal picture and gradient regions due to down-sampling beforegradient calculation.

The generated gradient slope mask and gradient direction map are thenused in the encoder to make better coding decisions. Generally speaking,the results generated by a gradient slope region detector can be used byan encoder to make other coding decisions. For example, an encoder canmake quantization decisions based on a generated gradient slope maskand/or gradient direction map. Some of the possible encoder decisionsare described below.

VI. Adjusting Quantization to Preserve Non-zero AC Coefficients

Typically, a picture is assigned a picture-level quantization parameterby a rate control unit in an encoder. Using the same picture-level QP,the amount of bits used to represent a highly textured macroblock istypically much greater (as much as 10 to 50 times greater) than theamount of bits used to represent a low textured macroblock. Since thehuman visual system is less sensitive to distortion in a busy, highlytextured area than in a smooth, low-textured area, however, it makessense to use a smaller QP for low textured macroblocks and a larger QPfor highly textured macroblocks.

This leads to the often-used strategy of classifying macroblocksaccording to human visual importance (usually using variance of theblocks or the strength of the gradients inside the blocks) and assigninga target number of bits proportional to some perceptual weighting. Thequantization parameter for each macroblock to be modified is selected bymodifying the picture level quantizer according to the weighting.

Experiments have shown that in smooth regions of very low variation,blocks are often quantized to have energy only in DC coefficients (withno non-zero AC coefficients remaining) even at a reasonably low QP.Surprisingly, when DC values in adjacent blocks in extremely smoothregions vary by only 1 from block-to-block, the perceived blocky,contouring artifact are a lot more severe than one would expect withsuch a small difference in absolute terms. The occurrence of this typeof artifact in relatively small regions inside an otherwise well-codedpicture can cause the overall perceived quality for the entire pictureto be lowered.

Traditional rate-distortion-based and perceptual-based macroblock QPselection techniques do not handle this situation well. Withrate-distortion optimization, the smooth blocks would be consideredwell-coded because of the small distortion in absolute terms, and thusno further bits would be spent for these blocks. On the other hand,typical perceptual-based methods classify macroblocks into perceptualclasses and assign a quantization parameter to each macroblock by addingor subtracting a pre-defined offset to the picture-level quantizationparameter according to the perceptual class of the macroblock. Unlessthe pre-defined offset is very aggressive (e.g., reducing QP for smoothregions to 1), such methods cannot guarantee that smooth blocks withsmall variations will not be quantized to a single non-zero DCcoefficient, with all AC coefficients quantized to zero. But setting avery aggressive offset can increase bits spent in macroblocks that maynot need them to improve perceptual quality, raising bit rateinefficiently and conflicting with the picture-level quantizationparameter selected by the encoder for rate control.

Accordingly, several techniques and tools described below selectivelyand judiciously allocate bits within pictures such that enough bits areallocated to smooth regions to reduce or remove introduction of blockingor contour artifacts.

For example, an encoder calculates QPs and selects a quantizationparameter for each macroblock within an I-picture to allocate enoughbits to smooth blocks, thereby reducing perceived blocking artifacts inthe I-picture. For each macroblock with one or more smooth blocks, a QPis selected such that there are at least N non-zero quantized ACcoefficients per block of the macroblock, where N is an integer greaterthan or equal to 1. Often, the preserved AC coefficients arecoefficients for the lowest frequency AC basis functions of thetransform, which characterize gradual value changes horizontally and/orvertically across a block. This tends to help perceived visual qualityfor each block, especially for smooth regions with low variation. In oneimplementation, an encoder selects the largest QP, not exceeding thepicture QP, that still preserves AC coefficients as desired. There maybe situations (e.g., very flat blocks) that non-zero AC coefficients arenot preserved. In general, however, in this way, the encoder is notoverly aggressive in spending bits with smaller QPs and reduces oravoids conflict with the picture QP.

With reasonable values of N, the selected QP does not change for mostmacroblocks; it is the same as the picture QP for most macroblocks, andonly a few smooth blocks are affected. Reasonable values of N are 1, 2,3 or 4. The selected QP is more likely to change for macroblocks withlow texture. In one implementation, N=1 or 2 improves perceived qualitywithout too much increase in the picture's bit rate.

FIG. 30 shows an example technique 3000 for selecting a macroblock QP tohelp preserve one or more non-zero AC coefficients. An encoder such asthe encoder 1000 of FIG. 10 or other tool performs the technique 3000.

At 3010, the encoder finds the N^(th) largest AC coefficients of eachluma block of the macroblock. For example, the encoder finds the secondlargest AC coefficient of each of the four 8×8 blocks of a 16×16macroblock, if N=2. Let AC (0), AC (1), AC (2), AC (3) be the N^(th)largest coefficients for the four luma blocks 0, 1, 2 and 3,respectively. For different block organizations in a macroblock, theN^(th) coefficients can come from more or fewer blocks in themacroblock.

At 3020, the encoder finds the minimum of these N^(th) coefficientvalues. For the N^(th) O coefficients of four blocks, AC_(min)=min (AC(0), AC (1), AC (2), AC (3)). For other numbers of blocks, ACE_(min) iscomputed differently.

At 3030, the encoder sets a QP for the macroblock such that AC_(min) isoutside the dead zone threshold for that QP. The dead zone threshold isa “cut-off” threshold for quantizing an AC coefficient to zero when thevalue of QP is used for quantization. The dead zone threshold is usuallypredetermined for, and proportional to, a given QP. The dead zonethreshold is selected at some point between 0 and the firstreconstruction point. When the encoder uses either a uniform quantizeror non-uniform quantizer, the first reconstruction point depends on theQP value and whether uniform or non-uniform quantization is used. In oneimplementation, the first reconstruction point is the reconstructedvalue of quantized coefficient level=1, which for uniform quantizationis 2*QP and for non-uniform quantization is 3*QP. For uniformquantization, the cut-off threshold thus lies between 0 and 2*QP. Fornon-uniform quantization, the cut-off threshold thus lies between 0 and3*QP. For example, the dead zone threshold Z(QP) is selected asZ(QP)=6*QP/5 for uniform quantization, and Z(QP)=2*QP for non-uniformquantization. Alternatively, other cut-off thresholds can be used.

An AC coefficient AC will be quantized to zero if: Abs(AC)<Z(QP). To set(3030) the QP for a macroblock, an encoder can find the QP for themacroblock (QP_(m)) that will preserve at least N AC coefficients bycomparing AC_(min) with Z(QP) for candidate values of QP, starting withthe picture QP and decreasing QP until a minimum QP for the quantizer isreached (e.g., QP=1) or the inequality Abs(AC_(min))>=Z(QP) issatisfied. If the inequality Abs(AC_(min))>=Z(QP) is satisfied, theencoder sets the threshold QP for the macroblock to be the first QP(i.e., highest qualifying QP) that satisfies the inequality.Alternatively, the encoder uses other logic to compute the QP for themacroblock, for example, starting from the lowest QP or using a binarysearch of QP values.

The process of using QP_(m) to quantize all blocks in the macroblock canbe referred to as unconstrained bit rate quantization. In a constrainedbit rate quantization technique, an encoder determines the maximum QP(not greater than the picture QP) needed to produce the desired numberof non-zero AC coefficients for each of the luma blocks of themacroblock separately (e.g., QP₀, QP₁, QP₂, and QP₃ for blocks 0, 1, 2and 3, respectively) as described above. It follows that QP_(m) equalsthe minimum of QP₀, QP₁, QP₂, and QP₃. To reduce bit usage, an encodercould use QP_(i) to quantize block i (where i=0, 1, 2, 3, etc.) in placeof QP_(m). In an encoder that specifies a single QP for an entiremacroblock, the encoder can instead keep only those AC coefficients thatare non-zero when quantized using QP_(i) for each block i whenquantizing the block using QP_(m), preserving only the top N non-zero ACcoefficients in a given block even if other AC coefficients in the blockwould be preserved with quantization by QP_(m). For the quantizationprocess shown in FIG. 30, the quantization process for each luma blockcan be performed as a two-pass process. In the first pass, the encoder“thresholds” DCT coefficients to zero if the coefficient is less thanZ(QP_(i)), and otherwise keeps the same DCT coefficients. Then, the“thresholded” DCT coefficients are quantized in the same manner usingQP_(m).

Alternatively, an encoder preserves non-zero AC coefficients in someother way. For example, an encoder can select a QP on a basis other thana macroblock-by-macroblock basis (e.g., block-by-block basis). Theencoder can preserve AC coefficient for I-pictures, P-pictures, orB-pictures, or combinations thereof.

If at the minimum possible QP the number of non-zero quantizedcoefficients is less than N,N can be adjusted accordingly.

VI. Differential Quantization on DC Shift

In a typical lossy encoding scenario, not all quantized DC and ACcoefficients can be recovered exactly after inverse quantization. Forexample, in some video codecs, DC coefficient values shift by one (i.e.,increase or decrease by one relative to their pre-quantization value)for some QPs and DC coefficient values. This phenomenon is an example ofDC shift. Representations of some DC coefficient values are losslessthrough quantization and inverse quantization at one or more lower QPs,but lossy in other, higher QPs.

A region with several blocks in which all the AC coefficients arequantized to 0 and the DC coefficients cannot be recovered exactly canexhibit visible contouring artifacts in DC shift areas. Such regionswith contouring artifacts are often smooth, gradient slope regions, suchas sky, water or light rays. FIG. 31 is a diagram showing a DC shift inthree neighboring blocks in a gradient slope region after quantizationand inverse quantization. The DC values of three neighboring blocks3102, 3104, 3106 in a gradient slope region are 68, 69, and 70,respectively, prior to quantization. After quantization and inversequantization, the DC value of block 3104 is shifted to 70. As shown inFIG. 31, the DC values of the three neighboring blocks are now 68, 70,and 70. When such blocks are in a gradient slope region, the quantizedDC values may cause perceptible contouring artifacts. For example,referring again to FIGS. 22A-C, the gradient slope region 2210 has beenquantized, resulting in a visible contouring artifact in FIG. 22B. Asshown in FIG. 22C, quantization of the DC coefficients for the top-halfblocks of macroblock 2250 results in uniform values reconstructed from aDC value of 68, while quantization of DC coefficients for thebottom-half blocks results in uniform values reconstructed from a DCvalue of 70.

Accordingly, several techniques and tools described below are used by avideo encoder to detect DC shift areas and adjust quantization to reduceor avoid introduction of contouring artifacts in the DC shift areas.

FIG. 32 is a flow chart showing a generalized technique 3200 foradjusting quantization to reduce or avoid introduction of contouringartifacts in DC shift areas. An encoder such as the encoder 1000 of FIG.10 or other tool performs the technique 3200.

At 3210, an encoder detects a shift area. The search for DC shift areascan be aided by previous gradient slope detection. For example, theencoder detects DC shift areas by detecting one or more gradient sloperegions (or using previously computed gradient slope detectioninformation) then identifying DC shift blocks in the gradient sloperegion(s), as described below.

At 3220, the encoder adjusts quantization in the DC shift area. Forexample, an encoder can use differential quantization (DQ) to code DCshift blocks in order to reduce or avoid introduction of contouringartifacts caused by DC shift. The encoder reduces QP for somemacroblocks (those with DC shift blocks) but does not change QP forother blocks. Reducing QP for macroblocks having DC shift blocks canhelp keep DC values lossless for the macroblocks, thereby reducing oravoiding introduction of contouring artifacts. An encoder can usebi-level DQ or multi-level DQ to resolve DC shift problems and therebyimprove visual quality while controlling bit usage. If there are morepictures to analyze, the encoder processes the next picture (3230).

Alternatively, the encoder adjusts quantization for DC shift areas on amacroblock-by-macroblock basis or some other basis.

A. Gradient Slope Detection

Gradient slope detection can be used to identify one or more gradientslope regions in a picture. The gradient slope region(s) tend to exhibitcontouring artifacts, especially when blocks in the region(s) havenon-zero DC coefficient values and AC coefficients of only zero afterquantization. Once found, such region(s) can be checked for DC shiftblocks that may contribute to contouring artifacts.

For example, an encoder finds a gradient slope region using a techniquedescribed herein (Section V) or some other technique. If the onlynon-zero coefficients in blocks are DC coefficients after quantization,the encoder treats the blocks as candidates for DC shift areaadjustment. Alternatively, the encoder considers additional blocks ascandidates for DC shift area adjustment.

B. Identifying DC-shift blocks

The encoder identifies certain candidate blocks as DC shift blocks. Theidentification of DC shift blocks depends on details of the quantizerand QPs used to compress the blocks. For example, some reconstructed DCcoefficients will not shift from their original value at one QP, butwill shift at a coarser QP.

Examples of DC shift coefficients for different QPs in one encoder areprovided in the following table. The table indicates DC coefficientvalues exhibiting DC shift for different values of QP, where QP isderived explicitly from the parameter PQIndex (and, potentially, a halfstep parameter) or implicitly from the parameter PQIndex (and,potentially, a half step parameter). DC values not listed in the tableare lossless for the indicated QP in the example encoder; DC values forQPs under 3 (which are not shown in the table) are all lossless. Theexample encoder does not perform DC shift adjustment for QPs higher thanthose shown in the table. In the example encoder, quantization of DCcoefficients is the same for different quantizers (e.g., uniform,non-uniform). Which DC coefficient values are DC shift coefficients willdiffer in different video codecs. Different quantizers (e.g., uniform,non-uniform) can result in different shift patterns if quantization ofDZ coefficients is different in the different quantizers.

TABLE 3 Example DC-shift Coefficients PQIndex PQIndex Orig- Orig- Orig-(Implicit (Explicit inal Shifted inal Shifted inal Shifted QP) QP) DC DCDC DC DC DC 3-5.5 3-5.5 6 7 96 97 186 187 15 16 105 106 195 196 24 25114 115 204 205 33 34 123 124 213 214 42 43 132 133 222 223 51 52 141142 231 232 60 61 150 151 240 241 69 70 159 160 249 250 78 79 168 169 8788 177 178 6-7.5, 6-7.5 2 1 92 93 178 177 9-10.5 6 7 97 96 183 182 11 12102 101 187 188 16 15 106 107 192 193 21 20 111 112 197 196 25 26 116115 202 201 30 31 121 120 207 206 35 34 126 125 211 212 40 39 158 157216 217 45 44 130 131 221 220 49 50 135 136 225 226 54 53 140 139 230231 59 58 144 145 235 236 63 64 149 150 240 239 68 69 154 155 245 244 7374 159 158 249 250 78 77 164 163 254 255 83 82 168 169 87 88 173 174 8,11-12 8-9 2 1 88 89 171 172 5 6 92 91 175 174 9 8 95 96 178 179 12 11 9998 182 181 15 16 102 101 185 186 19 18 105 106 189 188 22 23 109 108 192191 26 25 112 113 195 196 29 30 116 115 199 198 33 32 119 120 202 203 3637 123 122 206 205 40 39 126 127 209 210 43 44 158 156 213 212 47 46 130129 216 217 50 51 133 134 220 219 54 53 137 136 223 224 57 56 140 141227 226 60 61 144 143 230 231 64 63 147 146 234 233 67 68 150 151 237236 71 70 154 153 240 241 74 75 157 158 244 243 78 77 161 160 247 248 8182 164 165 251 250 85 84 168 167 254 255 13-14 10-11 2 3 90 89 175 174 54 93 92 177 178 8 7 95 96 180 181 11 10 98 99 183 184 13 14 101 102 186185 16 17 104 103 189 188 19 20 107 106 192 191 22 21 110 109 194 195 2524 112 113 197 198 27 28 115 116 200 201 30 31 118 119 203 202 33 34 121120 206 205 36 35 124 123 209 208 39 38 126 127 211 212 42 41 158 157214 215 45 44 129 130 217 218 47 48 132 133 220 219 50 51 135 136 223222 53 52 138 137 225 226 56 55 141 140 228 229 59 58 144 143 231 232 6162 146 147 234 235 64 65 149 150 237 236 67 68 152 151 240 239 70 69 155154 243 242 73 72 158 157 245 246 76 75 160 161 248 249 78 79 163 164251 250 81 82 166 167 254 253 84 85 169 168 87 86 172 171 15-16 12-13 21 87 88 171 170 4 3 90 89 173 174 6 7 92 93 176 175 9 8 95 94 178 179 1112 97 98 181 180 14 13 100 99 183 184 16 17 102 103 186 185 19 18 105104 188 189 21 22 107 108 191 190 24 23 110 109 193 194 26 27 112 111195 196 29 28 114 115 198 197 31 30 117 116 200 201 33 34 119 120 203202 36 35 122 121 205 206 38 39 124 125 208 207 41 40 127 126 210 211 4344 158 157 213 212 46 45 129 130 215 216 48 49 132 131 218 217 51 50 134135 220 221 53 54 137 136 222 223 56 55 139 140 225 224 58 57 141 142227 228 60 61 144 143 230 229 63 62 146 147 232 233 65 66 149 148 235234 68 67 151 152 237 238 70 71 154 153 240 239 73 72 156 157 242 243 7576 159 158 245 244 78 77 161 162 247 248 80 81 164 163 249 250 83 82 166167 252 251 85 84 168 169 254 255 17-18 14-15 1 2 87 88 171 172 3 4 8990 173 174 5 6 92 91 175 176 8 7 94 93 178 177 10 9 96 95 180 179 12 1398 99 182 183 14 15 100 101 184 185 16 17 103 102 186 187 19 18 105 104189 188 21 20 107 106 191 190 23 24 109 110 193 194 25 26 111 112 195196 27 28 114 113 198 197 30 29 116 115 200 199 32 31 118 119 202 201 3435 120 121 204 205 36 37 122 123 206 207 39 38 125 124 209 208 41 40 127126 211 210 43 42 158 157 213 212 45 46 129 130 215 216 47 48 131 132217 218 50 49 133 134 220 219 52 51 136 135 222 221 54 53 138 137 224223 56 57 140 141 226 227 58 59 142 143 228 229 61 60 144 145 231 230 6362 147 146 233 232 65 66 149 148 235 236 67 68 151 152 237 238 69 70 153154 239 240 72 71 156 155 242 241 74 73 158 157 244 243 76 77 160 159246 247 78 79 162 163 248 249 81 80 164 165 250 251 83 82 167 166 253252 85 84 169 168 255 254

The example encoder with the DC shift coefficients shown in Table 3generally uses different QPs for textured regions than for smoothregions. The example encoder typically uses a QP in the range of 3-5 toencode smooth regions. As shown in Table 3, above, for QP 3-5, all theshifted DC values are 1 more than the original DC value. Other encodersmay use different QPs for smooth regions versus texture regions.

To help reduce or avoid introduction of contouring artifacts when DCshift blocks are detected, the example encoder changes the QP formacroblocks containing DC shift blocks to keep the DC values lossless inthose macroblocks. In particular, the example encoder reduces the QP formacroblocks containing DC shift blocks to QP=2. (Other encoders may usesome other QP for DC shift areas.) In general, an encoder can select thelargest available QP that results in lossless treatment of the DCcoefficients of the blocks of the macroblock.

An encoder calculates a mean luma value per block to determine DC shiftblocks in the gradient slope region(s), since the mean luma valuecorresponds to the DC shift value (after compensating for expansion inthe transform). The mean luma value allows the encoder to estimate orpredict which blocks have DC shifts. Alternatively, an encodercalculates real DC values and looks them up in the DC shift table toidentify exactly which blocks will have shifts.

The encoder can perform additional processing to exclude certainisolated DC shift blocks in the gradient slope region(s). In the exampleencoder, once a current block is identified as a DC shift block locatedin a gradient slope region, the surrounding four neighboring blocks arechecked. If any of the surrounding four neighboring blocks is a smoothblock and has a DC value lower than the shifted DC value of the currentblock, the encoder uses QP=2 to for the macroblock containing thecurrent block in order to keep the DC values lossless. Alternatively, anencoder does not do a check of neighboring blocks, or checks some otherarrangement of neighboring blocks to determine whether to make a changein the QP for the DC shift area.

C. Multi-level Differential Quantization Cost Model

Bi-level DQ and multi-level DQ typically have different bit rate costs.In one implementation, 1 bit per macroblock is used to signal a pictureQP or alternative QP in “all macroblock” bi-level DQ, and at least 3bits per macroblock are used to signal a picture QP or alternative QPsin multi-level DQ.

Although an encoder can use multi-level DQ to allow for reducing QP in asmooth region that contains DC shift blocks, an encoder instead canchoose to adjust the QP for all smooth regions (e.g., to QP=2) and use acoarser picture QP for the rest of the picture in a bi-level DQscenario. For example, an encoder may do this where the signaling costsof multi-level DQ are found to be too expensive relative to the costs ofbi-level DQ.

In one implementation, the following table is used to calculate the costof smooth blocks that going from QP=3, 4, 5, and 6, respectively, toQP=2.g_iSmoothBlockDiffQPCost[4]={18, 22, 28, 36}.

This table is used in the following example of bi-level DQ cost B(QP)cost calculation.B(QP)=counts_of_total_(—) MBs+(counts_of_biLevel_(—) Dquan_(—)MBs−counts_of_(—) DC_Shift_Blocks)*g _(—) iSmoothBlockDiffQPCost[QP-3];

The cost B(QP) accounts for the costs of per-macroblock bi-level costsignaling and estimates the increased bit cost of using QP=2 instead ofa 3, 4, 5, or 6 for a block. Multi-level DQ cost M(QP) is calculated as:M(QP)=(counts_of_frameQP _(—) MBs*3)+(counts_of_biLevel_(—) Dquan_(—)MBs−counts_of_(—) DC_Shift_Blocks)*8+(counts_of_(—) DC_Shift_Blocks*3);The cost M(QP) accounts for signaling costs of multi-level DQ, assumingescape coding for some macroblock quantization parameters. IfB(qp)<M(qp), then bi-level DQ will be used and QP=2 will be used for allsmooth blocks. Otherwise, multi-level DQ will be used.

Alternatively, an encoder uses other costs models for different types orconfigurations of DQ. Or, an encoder reduces QP for the entire picturewhen DC shift blocks are detected, or uses some other technique tochange quantization to reduce or avoid introduction contouring artifactswhen DC shift blocks are detected.

D. Picture QP switching

In one example encoder, multi-level DQ requires 3 bits to signal any QPfrom picture QP to picture QP+6. Any QP outside of this range will besignaled with 8 bits through escape coding. Alternative QPs that areused for smooth regions are normally smaller than the picture QP, andhence require escape coding.

Switching picture QPs can thus save coding overhead for multi-level DQ.For example, an encoder can choose a picture QP using the multi-level DQcost model described above. For example, for a three-level scenario(e.g., a picture QP, a smooth region QP, and a DC shift QP), multi-levelDQ cost is computed for different candidate values for a picture QP. Anencoder can select the picture QP with minimum overhead cost.

Alternatively, an encoder uses other criteria to switch picture QPs, ordoes not perform picture QP switching.

E. Coarse Quantization for High-texture Macroblocks

If a decision is made to use multi-level DQ, coarse quantization can beused for high-texture macroblocks by assigning them a higher (coarser)QP than the picture QP. The decision to use multi-level DQ for thepicture (e.g., in order to use smaller QP for DC shift macroblocks)means there is no additional overhead cost to signal a per macroblockcoarse QP that is higher than the picture QP. For example, picture QP+1can used as the coarse QP to avoid noticeable differences in thequantization level, or some other QP can be used. A texture thresholdcan be used to determine which macroblocks will be quantized with thecoarse QP, after the encoder has decided to use multi-level DQ for thecurrent picture.

Alternatively, an encoder uses other criteria to determine whethercertain regions (e.g., macroblocks) should use a coarse QP, or does notuse coarse QPs.

F. Example Technique for DC Shift Quantization

FIG. 33 is a flow chart showing a combined technique 3300 for tailoringquantization in DC shift areas to reduce or avoid introduction ofquantization artifacts. An encoder such as the encoder 1000 of FIG. 10or other tool performs the technique 3300. This combined technique is anexample that combines several of the aspects described above. Othertechniques will not use all of the aspects described with reference tothis example, or will perform them in a different order or inalternative ways.

At 3310, an encoder detects one or more gradient slope regions in acurrent picture, for example, as described in Section V. At 3320, theencoder detects DC shift blocks in the gradient slope region(s), forexample, using a DC shift table.

The encoder then decides how to quantize the picture. At 3330, theencoder decides whether to use bi-level DQ for the picture. If it does,the encoder uses a QP smaller than the picture QP for DC shift areas(3340) and other smooth areas. Otherwise, at 3350, the encoder decideswhether to use multi-level DQ for the picture. If it does, the encoderuses a QP smaller than the picture QP for DC shift areas (3360), can usea different QP for other smooth areas, and, if high-texture macroblocksare present, uses a coarse QP (such as one that is larger than thepicture QP) for the high-texture macroblocks (3370). If the encoder doesnot choose bi-level or multi-level DQ, the encoder reduces the pictureQP and uses the reduced picture QP for DC shift areas (3380) as well asother areas. Or, the encoder skips QP reduction for the DC shift areasif the costs of bi-level DQ and multi-level DQ are both too high. Whenthe encoder has chosen a quantization scheme, the encoder compress thepicture at 3390, and process the next picture if any pictures remain tobe processed (3395).

Having described and illustrated the principles of our invention withreference to various embodiments, it will be recognized that the variousembodiments can be modified in arrangement and detail without departingfrom such principles. It should be understood that the programs,processes, or methods described herein are not related or limited to anyparticular type of computing environment, unless indicated otherwise.Various types of general purpose or specialized computing environmentsmay be used with or perform operations in accordance with the teachingsdescribed herein. Elements of embodiments shown in software may beimplemented in hardware and vice versa.

In view of the many possible embodiments to which the principles of ourinvention may be applied, we claim as our invention all such embodimentsas may come within the scope and spirit of the following claims andequivalents thereto.

1. In a video encoder, a method comprising: identifying a current smoothregion of a current video picture in a video picture sequence, the videopicture sequence having a display order in which display of pluralprevious pictures occurs before display of the current video picture inthe display order and display of plural future pictures occurs after thedisplay of the current video picture in the display order; performingtemporal analysis on the current smooth region, wherein the temporalanalysis comprises determining whether a corresponding region in atleast one of the plural previous and/or future pictures is smoothwherein the temporal analysis attributes greater weight to smoothness ina corresponding region of a future picture that is temporally nearer tothe current video picture than to smoothness in a corresponding regionof a future picture that is temporally more distant from the currentvideo picture; based at least in part on the temporal analysis,adjusting quantization in the current smooth region; and outputtingencoded data for the current video picture.
 2. The method of claim 1wherein the adjusting quantization in the current smooth regioncomprises reducing a quantization step size for the current smoothregion.
 3. The method of claim 2 wherein the reducing the quantizationstep size for the current smooth region avoids introduction of acontouring artifact in the current smooth region when the current videopicture is reconstructed.
 4. The method of claim 1 wherein the temporalanalysis is performed on an adjustable number of the plural futurepictures, and wherein the adjustable number is one or greater.
 5. Themethod of claim 1 wherein the current smooth region is a gradient sloperegion.
 6. The method of claim 1 wherein the video encoder analyzes atexture map to identify the current smooth region, and wherein the videoencoder analyzes mean luminance values in the temporal analysis.
 7. Oneor more computer-readable memory medium having stored thereon computerexecutable instructions to cause a computer to perform the method ofclaim
 1. 8. In a video encoder, a method comprising: analyzing texturein a current video picture; setting a smoothness threshold for thecurrent video picture based at least in part on the analyzed texture inthe current video picture; comparing texture data of the current videopicture with the smoothness threshold; adjusting differentialquantization for at least part of the current video picture based on afinding of at least one smooth region in the current video pictureaccording to the smoothness threshold, wherein adjusting thedifferential quantization includes determining a percentage of flatblocks in the current video picture and comparing the percentage to oneor more percentage thresholds; and outputting encoded data for thecurrent video picture.
 9. The method of claim 8 wherein the analyzingtexture comprises analyzing a texture map.
 10. The method of claim 8wherein the analyzing texture comprises applying a sliding window to agradient value histogram of block gradient values.
 11. The method ofclaim 8 wherein the adjusting differential quantization depends onresults of the comparing the percentage to the one or more percentagethresholds.
 12. The method of claim 8 wherein the adjusting differentialquantization comprises: identifying an isolated flat block in a textureregion in the current video picture; and skipping the differentialquantization for the isolated flat block.